From 3bd76833d9cb1fffa5e4bce02a59a0fec53de993 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Apr 2022 07:06:15 +0000 Subject: [PATCH 01/96] Auto-generated commit 2babfd77e9a6a04524bc2a69d66c49495c719166 --- index.d.ts | 228 +++++ index.mjs | 4 + index.mjs.map | 1 + stats.html | 2689 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 2922 insertions(+) create mode 100644 index.d.ts create mode 100644 index.mjs create mode 100644 index.mjs.map create mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..abb46f6 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,228 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +import { ArrayLike } from '@stdlib/types/array'; +import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; + +/** +* Interface defining function options. +*/ +interface Options { + /** + * 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) (default: 'float64'). + */ + dtype?: DataType; + + /** + * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). + */ + order?: Order; + + /** + * Specifies how to handle indices which exceed array dimensions (default: 'throw'). + */ + mode?: Mode; + + /** + * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). + */ + submode?: Array; + + /** + * Boolean indicating whether to copy source data to a new data buffer (default: false). + */ + copy?: boolean; + + /** + * Boolean indicating whether to automatically flatten generic array data sources (default: true). + */ + flatten?: boolean; + + /** + * Minimum number of dimensions (default: 0). + */ + ndmin?: number; + + /** + * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). + */ + casting?: string; + + /** + * Boolean indicating if an array should be read-only (default: false). + */ + readonly?: boolean; +} + +/** +* Interface describing function options. +*/ +interface OptionsWithShape extends Options { + /** + * Array shape. + */ + shape: Shape; + + /** + * Data source. + * + * ## Notes + * + * - If provided along with a `buffer` argument, the argument takes precedence. + */ + buffer?: ArrayLike; +} + +/** +* Interface describing function options. +*/ +interface OptionsWithBuffer extends Options { + /** + * Array shape. + */ + shape?: Shape; + + /** + * Data source. + * + * ## Notes + * + * - If provided along with a `buffer` argument, the argument takes precedence. + */ + buffer: ArrayLike; +} + +/** +* Interface describing function options. +*/ +interface ExtendedOptions extends Options { + /** + * Array shape. + */ + shape?: Shape; + + /** + * Data source. + * + * ## Notes + * + * - If provided along with a `buffer` argument, the argument takes precedence. + */ + buffer?: ArrayLike; +} + +/** +* Returns a multidimensional array. +* +* @param options - function options +* @param options.buffer - data source +* @param options.dtype - 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) (default: 'float64') +* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') +* @param options.shape - array shape +* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') +* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) +* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) +* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) +* @param options.ndmin - minimum number of dimensions (default: 0) +* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') +* @param options.readonly - boolean indicating whether an array should be read-only +* @throws must provide valid options +* @throws must provide either an array shape, data source, or both +* @throws invalid cast +* @throws data source must be compatible with specified meta data +* @returns ndarray instance +* +* @example +* var opts = { +* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], +* 'dtype': 'generic', +* 'flatten': false +* }; +* +* var arr = array( opts ); +* // returns +* +* var v = arr.get( 0 ); +* // returns [ 1, 2 ] +*/ +declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length + +/** +* Returns a multidimensional array. +* +* @param buffer - data source +* @param options - function options +* @param options.buffer - data source +* @param options.dtype - 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) (default: 'float64') +* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') +* @param options.shape - array shape +* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') +* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) +* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) +* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) +* @param options.ndmin - minimum number of dimensions (default: 0) +* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') +* @param options.readonly - boolean indicating whether an array should be read-only +* @throws must provide valid options +* @throws must provide either an array shape, data source, or both +* @throws invalid cast +* @throws data source must be compatible with specified meta data +* @returns ndarray instance +* +* @example +* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); +* // returns +* +* var v = arr.get( 0, 0 ); +* // returns 1 +* +* @example +* var opts = { +* 'dtype': 'generic', +* 'flatten': false +* }; +* +* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); +* // returns +* +* var v = arr.get( 0 ); +* // returns [ 1, 2 ] +* +* @example +* var Float64Array = require( '@stdlib/array-float64' ); +* +* var opts = { +* 'shape': [ 2, 2 ] +* }; +* +* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); +* // returns +* +* var v = arr.get( 0, 0 ); +* // returns 1.0 +*/ +declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = array; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6fcf7e6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";var O=v,k=w;var z=function(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&k(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) 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 getType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flattenArray = require( '@stdlib/utils-flatten-array' );\nvar format = require( '@stdlib/string-format' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar defaults = require( './defaults.json' );\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// 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 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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 ( 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 = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\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 array = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = array;\n"],"names":["PINF","require$$0","isInteger","require$$1","is_array_like_object","value","length","bufferCtors","allocUnsafe","cast_buffer","buffer","len","dtype","ctor","out","i","push","copy_view","arr","get","generic","binary","typed","expand_shape","ndims","shape","ndmin","abs","expand_strides","strides","order","N","s","j","hasOwnProp","isObject","isBoolean","require$$2","isPrimitive","isArray","require$$3","isNonNegativeInteger","require$$4","isndarrayLike","require$$5","shape2strides","require$$6","strides2offset","require$$7","strides2order","require$$8","numel","require$$9","ndarray","require$$10","isDataType","require$$11","isOrder","require$$12","isCastingMode","require$$13","isAllowedCast","require$$14","createBuffer","require$$15","getType","require$$16","arrayShape","require$$17","flattenArray","require$$18","format","require$$19","isArrayLikeObject","require$$20","defaults","require$$21","castBuffer","require$$22","copyView","require$$23","expandShape","require$$24","expandStrides","require$$25","main","options","offset","btype","nopts","opts","FLG","arguments","TypeError","casting","flatten","Error","mode","submode","readonly","copy","RangeError","data","lib"],"mappings":";;suEAsBA,IAAIA,EAAOC,EACPC,EAAYC,EAkChB,IAAAC,EAdA,SAA4BC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbJ,EAAWG,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASN,4GC5BbO,EAAcN,EACdO,EAAcL,EA8ClB,IAAAM,EA5BA,SAAqBC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAON,EAAaK,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIE,KAAMN,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMN,EAAaG,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,GCzCJP,EAAcN,EACdO,EAAcL,EAwGlB,IAAAc,EAdA,SAAmBC,EAAKN,GAEvB,MAAe,YAAVA,EAhFN,SAAkBM,GACjB,IAAIP,EACAG,EACAC,EAIJ,IAFAJ,EAAMO,EAAIZ,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIE,KAAME,EAAIC,IAAKJ,IAEpB,OAAOD,EAuECM,CAASF,GAEF,WAAVN,EA/DN,SAAiBM,GAChB,IAAIP,EACAG,EACAC,EAIJ,IAFAJ,EAAMO,EAAIZ,OACVQ,EAAMN,EAAaG,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMG,EAAIC,IAAKJ,GAErB,OAAOD,EAsDCO,CAAQH,GA3CjB,SAAgBA,EAAKN,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCP,EAAaK,GAEd,CADND,EAAMO,EAAIZ,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMG,EAAIC,IAAKJ,GAErB,OAAOD,EAiCAQ,CAAOJ,EAAKN,ICzEpB,IAAAW,EAjBA,SAAsBC,EAAOC,EAAOC,GACnC,IAAIZ,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIW,EAAMF,EAAOT,IAC7BD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAIS,EAAOT,IACvBD,EAAIE,KAAMS,EAAOV,IAElB,OAAOD,GCpBJa,EAAM1B,EAuDV,IAAA2B,EAhCA,SAAwBJ,EAAOC,EAAOI,EAASC,GAC9C,IAAIhB,EACAiB,EACAC,EACAjB,EACAkB,EAKJ,GAFAA,EAAIT,GADJO,EAAIF,EAAQvB,QAEZQ,EAAM,GACS,cAAVgB,EAAwB,CAE5B,IADAE,EAAIL,EAAKE,EAAS,IAAQJ,EAAOQ,GAC3BlB,EAAI,EAAGA,EAAIkB,EAAGlB,IACnBD,EAAIE,KAAMgB,GAEX,IAAMjB,EAAI,EAAGA,EAAIgB,EAAGhB,IACnBD,EAAIE,KAAMa,EAASd,QAEd,CACN,IAAMA,EAAI,EAAGA,EAAIkB,EAAGlB,IACnBD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAIgB,EAAGhB,IACnBD,EAAIE,KAAMa,EAASd,IAGrB,OAAOD,GCjDJoB,EAAajC,EACbkC,EAAWhC,EACXiC,EAAYC,EAAuCC,YACnDC,EAAUC,EACVC,EAAuBC,EAAmDJ,YAC1EK,EAAgBC,EAChBC,EAAgBC,EAChBC,EAAiBC,EACjBC,EAAgBC,EAChBC,EAAQC,EACRC,EAAUC,EACVC,EAAaC,EACbC,EAAUC,EACVC,EAAgBC,EAChBC,EAAgBC,EAChBC,EAAeC,EACfC,GAAUC,EACVC,GAAaC,EACbC,GAAeC,EACfC,GAASC,EACTC,GAAoBC,EACpBC,GAAWC,EACXC,GAAaC,EACbC,GAAWC,EACXC,GAAcC,EACdC,GAAgBC,EA6RpB,IAAAC,GAjOA,WACC,IAAIC,EACAzD,EACAnB,EACA6E,EACAzD,EACAlB,EACA4E,EACA/D,EACAD,EACAiE,EACAC,EACA/E,EAEAgF,EAEJ,GAA0B,IAArBC,UAAUtF,OACd,GAAKmE,GAAmBmB,UAAW,IAClClF,EAASkF,UAAW,GACpBN,EAAU,OACJ,CAEN,IAAMnD,EADNmD,EAAUM,UAAW,IAEpB,MAAM,IAAIC,UAAWtB,GAAQ,qGAAsGe,IAEpI,GAAKpD,EAAYoD,EAAS,YACzB5E,EAAS4E,EAAQ5E,QACX+D,GAAmB/D,IACxB,MAAM,IAAImF,UAAWtB,GAAQ,qHAAsH,SAAU7D,QAI1J,CAEN,IAAM+D,GADN/D,EAASkF,UAAW,IAEnB,MAAM,IAAIC,UAAWtB,GAAQ,oHAAsH7D,IAGpJ,IAAMyB,EADNmD,EAAUM,UAAW,IAEpB,MAAM,IAAIC,UAAWtB,GAAQ,qEAAsEe,IAiBrG,GAbK5E,IACCiC,EAAejC,IACnB8E,EAAQ9E,EAAOE,MACf+E,GAAM,IAENH,EAAQvB,GAASvD,GACjBiF,GAAM,IAGRF,EAAQ,GACRC,EAAO,GAGFxD,EAAYoD,EAAS,YAEzB,GADAI,EAAKI,QAAUR,EAAQQ,SACjBnC,EAAe+B,EAAKI,SACzB,MAAM,IAAID,UAAWtB,GAAQ,+EAAgF,UAAWmB,EAAKI,eAG9HJ,EAAKI,QAAUnB,GAASmB,QAEzB,GAAK5D,EAAYoD,EAAS,YAEzB,GADAI,EAAKK,QAAUT,EAAQS,SACjB3D,EAAWsD,EAAKK,SACrB,MAAM,IAAIF,UAAWtB,GAAQ,+DAAgE,UAAWmB,EAAKK,eAG9GL,EAAKK,QAAUpB,GAASoB,QAEzB,GAAK7D,EAAYoD,EAAS,UAEzB,GADAI,EAAKhE,MAAQ4D,EAAQ5D,OACfe,EAAsBiD,EAAKhE,OAChC,MAAM,IAAImE,UAAWtB,GAAQ,2EAA4E,QAASmB,EAAKhE,aAIxHgE,EAAKhE,MAAQiD,GAASjD,MAIvB,GAAKQ,EAAYoD,EAAS,SAAY,CAErC,GADA1E,EAAQ0E,EAAQ1E,OACV2C,EAAY3C,GACjB,MAAM,IAAIiF,UAAWtB,GAAQ,4EAA6E,QAAS3D,IAEpH,GAAK4E,IAAU3B,EAAe2B,EAAO5E,EAAO8E,EAAKI,SAChD,MAAM,IAAIE,MAAOzB,GAAQ,2FAA4FmB,EAAKI,QAASN,EAAO5E,SAS1IA,EAPU4E,IAILG,GAAiB,YAAVH,GAGJA,EAGDb,GAAS/D,MAElB,GAAKsB,EAAYoD,EAAS,UAEzB,GAAe,SADfxD,EAAQwD,EAAQxD,QACkB,SAAVA,EAClB6D,EAEW,QAAV7D,EAMHA,EADY,IAHPmB,EAAevC,EAAOmB,SAInB8C,GAAS7C,MAETpB,EAAOoB,MAIG,SAAVA,IACTA,EAAQpB,EAAOoB,OAGhBA,EAAQ6C,GAAS7C,WAEZ,IAAM2B,EAAS3B,GACrB,MAAM,IAAI+D,UAAWtB,GAAQ,wEAAyE,QAASzC,SAGhHA,EAAQ6C,GAAS7C,MAiBlB,GAfKI,EAAYoD,EAAS,QACzBG,EAAMQ,KAAOX,EAAQW,KAErBR,EAAMQ,KAAOtB,GAASsB,KAElB/D,EAAYoD,EAAS,WACzBG,EAAMS,QAAUZ,EAAQY,QAExBT,EAAMS,QAAU,CAAET,EAAMQ,MAEpB/D,EAAYoD,EAAS,YACzBG,EAAMU,SAAWb,EAAQa,SAEzBV,EAAMU,SAAWxB,GAASwB,SAEtBjE,EAAYoD,EAAS,SAEzB,GADAI,EAAKU,KAAOd,EAAQc,MACdhE,EAAWsD,EAAKU,MACrB,MAAM,IAAIP,UAAWtB,GAAQ,+DAAgE,OAAQmB,EAAKU,YAG3GV,EAAKU,KAAOzB,GAASyB,KAGtB,GAAKlE,EAAYoD,EAAS,SAAY,CAErC,GADA7D,EAAQ6D,EAAQ7D,OACVgD,GAAmBhD,GACxB,MAAM,IAAIoE,UAAWtB,GAAQ,0GAA2G,QAAS9C,IAElJD,EAAQC,EAAMnB,OACdK,EAAMwC,EAAO1B,OACP,CAAA,IAAKf,EAeX,MAAM,IAAIsF,MAAO,+EAdZL,GACJlE,EAAQf,EAAOe,MACfD,EAAQd,EAAOc,MACfb,EAAMD,EAAOJ,QACFoF,EAAKK,SAAWxD,EAAS7B,IAEpCc,GADAC,EAAQ0C,GAAYzD,IACNJ,OACdK,EAAMwC,EAAO1B,KAEbD,EAAQ,EAERC,EAAQ,CADRd,EAAMD,EAAOJ,SAYf,GALKkB,EAAQkE,EAAKhE,QACjBD,EAAQwD,GAAazD,EAAOC,EAAOiE,EAAKhE,OACxCF,EAAQkE,EAAKhE,OAGTiE,EAAM,CACV,GAAKjF,EAAOJ,SAAWK,EACtB,MAAM,IAAI0F,WAAY,wIAElBb,IAAU5E,GAAS8E,EAAKU,KAC5B1F,EAASqE,GAAUrE,EAAQE,IAE3BiB,EAAUnB,EAAOmB,QACjB0D,EAAS7E,EAAO6E,OAChB7E,EAASA,EAAO4F,KACXzE,EAAQvB,OAASkB,IAErBK,EAAUsD,GAAe3D,EAAOC,EAAOI,EAASC,UAG5C,GAAKpB,EAAS,CAIpB,GAHe,YAAV8E,GAAuBE,EAAKK,UAChCrF,EAAS2D,GAAc3D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAI0F,WAAY,yIAElBb,IAAU5E,GAAS8E,EAAKU,QAC5B1F,EAASmE,GAAYnE,EAAQC,EAAKC,SAGnCF,EAASqD,EAAcnD,EAAOD,GAO/B,YAJiB,IAAZkB,IACJA,EAAUgB,EAAepB,EAAOK,GAChCyD,EAASxC,EAAgBtB,EAAOI,IAE1B,IAAIwB,EAASzC,EAAOF,EAAQe,EAAOI,EAAS0D,EAAQzD,EAAO2D,IChQnEc,GALYtG"} \ No newline at end of file diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1147594 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + From 49e7a5e7c1069a7c65fd429587312855106bbcfe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 11 May 2022 20:38:17 +0000 Subject: [PATCH 02/96] Auto-generated commit --- .editorconfig | 181 --- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 -- .github/workflows/bundle.yml | 496 --------- .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 -- .github/workflows/npm_downloads.yml | 108 -- .github/workflows/productionize.yml | 160 --- .github/workflows/publish.yml | 157 --- .github/workflows/test.yml | 92 -- .github/workflows/test_bundles.yml | 158 --- .github/workflows/test_coverage.yml | 123 --- .github/workflows/test_install.yml | 83 -- .gitignore | 178 --- .npmignore | 227 ---- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --------- README.md | 47 +- benchmark/benchmark.js | 1209 --------------------- benchmark/python/numpy/benchmark.py | 284 ----- branches.md | 53 - docs/repl.txt | 159 --- docs/types/index.d.ts | 228 ---- docs/types/test.ts | 257 ----- examples/index.js | 48 - index.mjs | 2 +- index.mjs.map | 2 +- lib/cast_buffer.js | 70 -- lib/copy_view.js | 128 --- lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 -- lib/index.js | 71 -- lib/is_array_like_object.js | 58 - lib/main.js | 333 ------ package.json | 78 +- stats.html | 2 +- test/test.js | 126 --- 44 files changed, 25 insertions(+), 6068 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/bundle.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/index.d.ts delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/bundle.yml b/.github/workflows/bundle.yml deleted file mode 100644 index a9b11b8..0000000 --- a/.github/workflows/bundle.yml +++ /dev/null @@ -1,496 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: bundle - -# Workflow triggers: -on: - # Allow workflow to be manually run: - workflow_dispatch: - - # Run workflow upon completion of `productionize` workflow: - workflow_run: - workflows: ["productionize"] - types: [completed] - -# Workflow jobs: -jobs: - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, checkout branch and rebase on `main`: - - name: 'If `deno` exists, checkout branch and rebase on `main`' - if: steps.deno-branch-exists.outputs.remote-exists - continue-on-error: true - run: | - git checkout -b deno origin/deno - git rebase main -s recursive -X ours - while [ $? -ne 0 ]; do - git rebase --skip - done - - # If `deno` does not exist, checkout `main` and create `deno` branch: - - name: 'If `deno` does not exist, checkout `main` and create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout main - git checkout -b deno - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno --force - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Checkout production branch: - - name: 'Checkout production branch' - run: | - git fetch --all - git checkout -b production origin/production - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) bundle: - - name: 'Create Universal Module Definition (UMD) bundle' - id: umd-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'umd' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/index.d.ts b/docs/types/index.d.ts deleted file mode 100644 index 996b87c..0000000 --- a/docs/types/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/index.mjs b/index.mjs index 6fcf7e6..b7b1b60 100644 --- a/index.mjs +++ b/index.mjs @@ -1,4 +1,4 @@ // Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 /// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import n from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";var O=v,k=w;var z=function(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&k(e.length)&&e.length>=0&&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) 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 getType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flattenArray = require( '@stdlib/utils-flatten-array' );\nvar format = require( '@stdlib/string-format' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar defaults = require( './defaults.json' );\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// 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 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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 ( 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 = copyView( buffer, dtype );\n\t\t} else {\n\t\t\tstrides = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\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 array = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = array;\n"],"names":["PINF","require$$0","isInteger","require$$1","is_array_like_object","value","length","bufferCtors","allocUnsafe","cast_buffer","buffer","len","dtype","ctor","out","i","push","copy_view","arr","get","generic","binary","typed","expand_shape","ndims","shape","ndmin","abs","expand_strides","strides","order","N","s","j","hasOwnProp","isObject","isBoolean","require$$2","isPrimitive","isArray","require$$3","isNonNegativeInteger","require$$4","isndarrayLike","require$$5","shape2strides","require$$6","strides2offset","require$$7","strides2order","require$$8","numel","require$$9","ndarray","require$$10","isDataType","require$$11","isOrder","require$$12","isCastingMode","require$$13","isAllowedCast","require$$14","createBuffer","require$$15","getType","require$$16","arrayShape","require$$17","flattenArray","require$$18","format","require$$19","isArrayLikeObject","require$$20","defaults","require$$21","castBuffer","require$$22","copyView","require$$23","expandShape","require$$24","expandStrides","require$$25","main","options","offset","btype","nopts","opts","FLG","arguments","TypeError","casting","flatten","Error","mode","submode","readonly","copy","RangeError","data","lib"],"mappings":"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"} \ No newline at end of file +{"version":3,"file":"index.mjs","sources":["../lib/is_array_like_object.js","../lib/cast_buffer.js","../lib/copy_view.js","../lib/expand_shape.js","../lib/expand_strides.js","../lib/main.js","../lib/index.js"],"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) 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 getType = require( '@stdlib/ndarray-base-buffer-dtype' );\nvar arrayShape = require( '@stdlib/array-shape' );\nvar flattenArray = require( '@stdlib/utils-flatten-array' );\nvar format = require( '@stdlib/error-tools-fmtprodmsg' );\nvar isArrayLikeObject = require( './is_array_like_object.js' );\nvar defaults = require( './defaults.json' );\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// 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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 array = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = array;\n"],"names":["PINF","require$$0","isInteger","require$$1","is_array_like_object","value","length","bufferCtors","allocUnsafe","cast_buffer","buffer","len","dtype","ctor","out","i","push","copy_view","arr","get","generic","binary","typed","expand_shape","ndims","shape","ndmin","abs","expand_strides","strides","order","N","s","j","hasOwnProp","isObject","isBoolean","require$$2","isPrimitive","isArray","require$$3","isNonNegativeInteger","require$$4","isndarrayLike","require$$5","shape2strides","require$$6","strides2offset","require$$7","strides2order","require$$8","numel","require$$9","ndarray","require$$10","isDataType","require$$11","isOrder","require$$12","isCastingMode","require$$13","isAllowedCast","require$$14","createBuffer","require$$15","getType","require$$16","arrayShape","require$$17","flattenArray","require$$18","format","require$$19","isArrayLikeObject","require$$20","defaults","require$$21","castBuffer","require$$22","copyView","require$$23","expandShape","require$$24","expandStrides","require$$25","main","options","offset","btype","nopts","opts","FLG","arguments","TypeError","casting","flatten","Error","mode","submode","readonly","copy","RangeError","data","lib"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index cadaf41..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 68331d4..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html index 1147594..ca54966 100644 --- a/stats.html +++ b/stats.html @@ -2669,7 +2669,7 @@ - - - - From 84f2ac83c5ae21632006b86e932697d2a6cd76d0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 07:39:12 +0000 Subject: [PATCH 05/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 2717 insertions(+), 5886 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 7563e33..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-06-30T22:53:11.663Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6297c75 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..34172e0 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From b4365ba2be1ceadae0d7b43c911b3e0aa16f56d5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Jul 2022 18:49:49 +0000 Subject: [PATCH 06/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From a6ab1cab157a6684268d74d5f11bddc7e1df52c6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 06:47:51 +0000 Subject: [PATCH 07/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6297c75..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":";;6wEA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,sECTjB,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,ECkDR,SAASK,EAAUC,EAAKR,GAEvB,MAAe,YAAVA,EAhFN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIC,IAAKN,IAEpB,OAAOD,EAuECQ,CAASF,GAEF,WAAVR,EA/DN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAsDCS,CAAQH,GA3CjB,SAAgBA,EAAKR,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAiCAU,CAAOJ,EAAKR,GC1FpB,SAASa,EAAaC,EAAOC,EAAOC,GACnC,IAAId,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIa,EAAMF,EAAOX,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIW,EAAOX,IACvBD,EAAIG,KAAMU,EAAOZ,IAElB,OAAOD,ECGR,SAASe,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjB,EACAkB,EACAC,EACAlB,EACAmB,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxB,QAEZQ,EAAM,GACS,cAAViB,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnB,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAMgB,GAEX,IAAMlB,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,QAEd,CACN,IAAMA,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,IAGrB,OAAOD,ECoCR,SAASsB,IACR,IAAIC,EACAP,EACApB,EACA4B,EACAP,EACAnB,EACA2B,EACAZ,EACAD,EACAc,EACAC,EACA9B,EAEA+B,EAEJ,GAA0B,IAArBC,UAAUrC,OACd,GAAKF,EAAmBuC,UAAW,IAClCjC,EAASiC,UAAW,GACpBN,EAAU,OACJ,CAEN,IAAMO,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,EAAYV,EAAS,YAEnBjC,EADNM,EAAS2B,EAAQ3B,QAEhB,MAAM,IAAImC,UAAWC,EAAQ,QAAS,SAAUpC,QAI7C,CAEN,IAAMN,EADNM,EAASiC,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASpC,IAGvC,IAAMkC,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAiBxC,GAbK3B,IACCsC,EAAetC,IACnB6B,EAAQ7B,EAAOE,MACf8B,GAAM,IAENH,EAAQU,EAASvC,GACjBgC,GAAM,IAGRF,EAAQ,GACRC,EAAO,GAGFM,EAAYV,EAAS,YAEzB,GADAI,EAAKS,QAAUb,EAAQa,SACjBC,EAAeV,EAAKS,SACzB,MAAM,IAAIL,UAAWC,EAAQ,QAAS,UAAWL,EAAKS,eAGvDT,EAAKS,QAAUE,EAEhB,GAAKL,EAAYV,EAAS,YAEzB,GADAI,EAAKY,QAAUhB,EAAQgB,SACjBC,EAAWb,EAAKY,SACrB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,UAAWL,EAAKY,eAGvDZ,EAAKY,QAAUD,EAEhB,GAAKL,EAAYV,EAAS,UAEzB,GADAI,EAAKb,MAAQS,EAAQT,OACf2B,EAAsBd,EAAKb,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASL,EAAKb,aAIrDa,EAAKb,MAAQwB,EAId,GAAKL,EAAYV,EAAS,SAAY,CAErC,GADAzB,EAAQyB,EAAQzB,OACV4C,EAAY5C,GACjB,MAAM,IAAIiC,UAAWC,EAAQ,QAAS,QAASlC,IAEhD,GAAK2B,IAAUkB,EAAelB,EAAO3B,EAAO6B,EAAKS,SAChD,MAAM,IAAIQ,MAAOZ,EAAQ,QAASL,EAAKS,QAASX,EAAO3B,SASvDA,EAPU2B,IAILG,GAAiB,YAAVH,GAGJA,EAGDa,EAET,GAAKL,EAAYV,EAAS,UAEzB,GAAe,SADfN,EAAQM,EAAQN,QACkB,SAAVA,EAClBW,EAEW,QAAVX,EAMHA,EADY,IAHP4B,EAAejD,EAAOoB,SAInBsB,EAEA1C,EAAOqB,MAIG,SAAVA,IACTA,EAAQrB,EAAOqB,OAGhBA,EAAQqB,OAEH,IAAMQ,EAAS7B,GACrB,MAAM,IAAIc,UAAWC,EAAQ,QAAS,QAASf,SAGhDA,EAAQqB,EAiBT,GAfKL,EAAYV,EAAS,QACzBG,EAAMqB,KAAOxB,EAAQwB,KAErBrB,EAAMqB,KAAOT,EAETL,EAAYV,EAAS,WACzBG,EAAMsB,QAAUzB,EAAQyB,QAExBtB,EAAMsB,QAAU,CAAEtB,EAAMqB,MAEpBd,EAAYV,EAAS,YACzBG,EAAMuB,SAAW1B,EAAQ0B,SAEzBvB,EAAMuB,SAAWX,EAEbL,EAAYV,EAAS,SAEzB,GADAI,EAAKuB,KAAO3B,EAAQ2B,MACdV,EAAWb,EAAKuB,MACrB,MAAM,IAAInB,UAAWC,EAAQ,QAAS,OAAQL,EAAKuB,YAGpDvB,EAAKuB,KAAOZ,EAGb,GAAKL,EAAYV,EAAS,SAAY,CAErC,IAAMjC,EADNuB,EAAQU,EAAQV,OAEf,MAAM,IAAIkB,UAAWC,EAAQ,QAAS,QAASnB,IAEhDD,EAAQC,EAAMrB,OACdK,EAAMsD,EAAOtC,OACP,KAAKjB,EAeX,MAAM,IAAIgD,MAAOZ,EAAQ,UAdpBJ,GACJf,EAAQjB,EAAOiB,MACfD,EAAQhB,EAAOgB,MACff,EAAMD,EAAOJ,QACFmC,EAAKY,SAAWa,EAASxD,IAEpCgB,GADAC,EAAQwC,EAAYzD,IACNJ,OACdK,EAAMsD,EAAOtC,KAEbD,EAAQ,EAERC,EAAQ,CADRhB,EAAMD,EAAOJ,SAYf,GALKoB,EAAQe,EAAKb,QACjBD,EAAQF,EAAaC,EAAOC,EAAOc,EAAKb,OACxCF,EAAQe,EAAKb,OAGTc,EAAM,CACV,GAAKhC,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,UAE1BP,IAAU3B,GAAS6B,EAAKuB,KAC5BtD,EAASS,EAAUT,EAAQE,IAE3BkB,EAAUpB,EAAOoB,QACjBQ,EAAS5B,EAAO4B,OAChB5B,EAASA,EAAO2D,KACXvC,EAAQxB,OAASoB,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,UAG5C,GAAKrB,EAAS,CAIpB,GAHe,YAAV6B,GAAuBE,EAAKY,UAChC3C,EAAS4D,EAAc5D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,WAE1BP,IAAU3B,GAAS6B,EAAKuB,QAC5BtD,EAASD,EAAYC,EAAQC,EAAKC,SAGnCF,EAAS6D,EAAc3D,EAAOD,GAO/B,YAJiB,IAAZmB,IACJA,EAAU0C,EAAe7C,EAAOI,GAChCO,EAASmC,EAAgB9C,EAAOG,IAE1B,IAAI4C,EAAS9D,EAAOF,EAAQiB,EAAOG,EAASQ,EAAQP,EAAOS"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 34172e0..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From ef9a8f83e8bd8af3899bf6249e3a845952f5b0fd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 2 Jul 2022 06:48:49 +0000 Subject: [PATCH 08/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 681 ------ .github/workflows/publish.yml | 157 -- .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 2717 insertions(+), 5886 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 240ff3a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-07-01T01:42:40.489Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 128c22e..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,681 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs rm -rf - - git add -A - git commit -m "Remove files" - - git merge -s recursive -X theirs origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6297c75 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ce66fe2 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 31dd24e22a9847404e62bae079dcf619ea97e620 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 18:44:27 +0000 Subject: [PATCH 09/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 960823072f9408fef6cd4b07ebe7a7957f10335b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:07:54 +0000 Subject: [PATCH 10/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6297c75..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ce66fe2..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 6e3b0dcc02575cac9db2891dc1e2878dfed9e143 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 6 Jul 2022 19:08:49 +0000 Subject: [PATCH 11/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 687 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 43 files changed, 2717 insertions(+), 5851 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 6726965..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,687 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the repository: - push: - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch or create new branch tag: - - name: 'Push changes to `deno` branch or create new branch tag' - run: | - SLUG=${{ github.repository }} - VERSION=$(echo ${{ github.ref }} | sed -E -n 's/refs\/tags\/?(v[0-9]+.[0-9]+.[0-9]+).*/\1/p') - if [ -z "$VERSION" ]; then - echo "Workflow job was not triggered by a new tag...." - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - else - echo "Workflow job was triggered by a new tag: $VERSION" - echo "Creating new bundle branch tag of the form $VERSION-deno" - git tag -a $VERSION-deno -m "$VERSION-deno" - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" $VERSION-deno - fi - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6297c75 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b6eac23 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From f9e8b87eb37ba5b66a31d64e505e7f26109f43bb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 03:58:03 +0000 Subject: [PATCH 12/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From d11a4902f8767e0e884c413ff077cbd7abad0dbd Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 18:05:30 +0000 Subject: [PATCH 13/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 6297c75..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":";;6wEA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,sECTjB,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,ECkDR,SAASK,EAAUC,EAAKR,GAEvB,MAAe,YAAVA,EAhFN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIC,IAAKN,IAEpB,OAAOD,EAuECQ,CAASF,GAEF,WAAVR,EA/DN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAsDCS,CAAQH,GA3CjB,SAAgBA,EAAKR,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAiCAU,CAAOJ,EAAKR,GC1FpB,SAASa,EAAaC,EAAOC,EAAOC,GACnC,IAAId,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIa,EAAMF,EAAOX,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIW,EAAOX,IACvBD,EAAIG,KAAMU,EAAOZ,IAElB,OAAOD,ECGR,SAASe,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjB,EACAkB,EACAC,EACAlB,EACAmB,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxB,QAEZQ,EAAM,GACS,cAAViB,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnB,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAMgB,GAEX,IAAMlB,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,QAEd,CACN,IAAMA,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,IAGrB,OAAOD,ECoCR,SAASsB,IACR,IAAIC,EACAP,EACApB,EACA4B,EACAP,EACAnB,EACA2B,EACAZ,EACAD,EACAc,EACAC,EACA9B,EAEA+B,EAEJ,GAA0B,IAArBC,UAAUrC,OACd,GAAKF,EAAmBuC,UAAW,IAClCjC,EAASiC,UAAW,GACpBN,EAAU,OACJ,CAEN,IAAMO,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,EAAYV,EAAS,YAEnBjC,EADNM,EAAS2B,EAAQ3B,QAEhB,MAAM,IAAImC,UAAWC,EAAQ,QAAS,SAAUpC,QAI7C,CAEN,IAAMN,EADNM,EAASiC,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASpC,IAGvC,IAAMkC,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAiBxC,GAbK3B,IACCsC,EAAetC,IACnB6B,EAAQ7B,EAAOE,MACf8B,GAAM,IAENH,EAAQU,EAASvC,GACjBgC,GAAM,IAGRF,EAAQ,GACRC,EAAO,GAGFM,EAAYV,EAAS,YAEzB,GADAI,EAAKS,QAAUb,EAAQa,SACjBC,EAAeV,EAAKS,SACzB,MAAM,IAAIL,UAAWC,EAAQ,QAAS,UAAWL,EAAKS,eAGvDT,EAAKS,QAAUE,EAEhB,GAAKL,EAAYV,EAAS,YAEzB,GADAI,EAAKY,QAAUhB,EAAQgB,SACjBC,EAAWb,EAAKY,SACrB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,UAAWL,EAAKY,eAGvDZ,EAAKY,QAAUD,EAEhB,GAAKL,EAAYV,EAAS,UAEzB,GADAI,EAAKb,MAAQS,EAAQT,OACf2B,EAAsBd,EAAKb,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASL,EAAKb,aAIrDa,EAAKb,MAAQwB,EAId,GAAKL,EAAYV,EAAS,SAAY,CAErC,GADAzB,EAAQyB,EAAQzB,OACV4C,EAAY5C,GACjB,MAAM,IAAIiC,UAAWC,EAAQ,QAAS,QAASlC,IAEhD,GAAK2B,IAAUkB,EAAelB,EAAO3B,EAAO6B,EAAKS,SAChD,MAAM,IAAIQ,MAAOZ,EAAQ,QAASL,EAAKS,QAASX,EAAO3B,SASvDA,EAPU2B,IAILG,GAAiB,YAAVH,GAGJA,EAGDa,EAET,GAAKL,EAAYV,EAAS,UAEzB,GAAe,SADfN,EAAQM,EAAQN,QACkB,SAAVA,EAClBW,EAEW,QAAVX,EAMHA,EADY,IAHP4B,EAAejD,EAAOoB,SAInBsB,EAEA1C,EAAOqB,MAIG,SAAVA,IACTA,EAAQrB,EAAOqB,OAGhBA,EAAQqB,OAEH,IAAMQ,EAAS7B,GACrB,MAAM,IAAIc,UAAWC,EAAQ,QAAS,QAASf,SAGhDA,EAAQqB,EAiBT,GAfKL,EAAYV,EAAS,QACzBG,EAAMqB,KAAOxB,EAAQwB,KAErBrB,EAAMqB,KAAOT,EAETL,EAAYV,EAAS,WACzBG,EAAMsB,QAAUzB,EAAQyB,QAExBtB,EAAMsB,QAAU,CAAEtB,EAAMqB,MAEpBd,EAAYV,EAAS,YACzBG,EAAMuB,SAAW1B,EAAQ0B,SAEzBvB,EAAMuB,SAAWX,EAEbL,EAAYV,EAAS,SAEzB,GADAI,EAAKuB,KAAO3B,EAAQ2B,MACdV,EAAWb,EAAKuB,MACrB,MAAM,IAAInB,UAAWC,EAAQ,QAAS,OAAQL,EAAKuB,YAGpDvB,EAAKuB,KAAOZ,EAGb,GAAKL,EAAYV,EAAS,SAAY,CAErC,IAAMjC,EADNuB,EAAQU,EAAQV,OAEf,MAAM,IAAIkB,UAAWC,EAAQ,QAAS,QAASnB,IAEhDD,EAAQC,EAAMrB,OACdK,EAAMsD,EAAOtC,OACP,KAAKjB,EAeX,MAAM,IAAIgD,MAAOZ,EAAQ,UAdpBJ,GACJf,EAAQjB,EAAOiB,MACfD,EAAQhB,EAAOgB,MACff,EAAMD,EAAOJ,QACFmC,EAAKY,SAAWa,EAASxD,IAEpCgB,GADAC,EAAQwC,EAAYzD,IACNJ,OACdK,EAAMsD,EAAOtC,KAEbD,EAAQ,EAERC,EAAQ,CADRhB,EAAMD,EAAOJ,SAYf,GALKoB,EAAQe,EAAKb,QACjBD,EAAQF,EAAaC,EAAOC,EAAOc,EAAKb,OACxCF,EAAQe,EAAKb,OAGTc,EAAM,CACV,GAAKhC,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,UAE1BP,IAAU3B,GAAS6B,EAAKuB,KAC5BtD,EAASS,EAAUT,EAAQE,IAE3BkB,EAAUpB,EAAOoB,QACjBQ,EAAS5B,EAAO4B,OAChB5B,EAASA,EAAO2D,KACXvC,EAAQxB,OAASoB,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,UAG5C,GAAKrB,EAAS,CAIpB,GAHe,YAAV6B,GAAuBE,EAAKY,UAChC3C,EAAS4D,EAAc5D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,WAE1BP,IAAU3B,GAAS6B,EAAKuB,QAC5BtD,EAASD,EAAYC,EAAQC,EAAKC,SAGnCF,EAAS6D,EAAc3D,EAAOD,GAO/B,YAJiB,IAAZmB,IACJA,EAAU0C,EAAe7C,EAAOI,GAChCO,EAASmC,EAAgB9C,EAAOG,IAE1B,IAAI4C,EAAS9D,EAAOF,EAAQiB,EAAOG,EAASQ,EAAQP,EAAOS"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b6eac23..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 83a23d20e72f5a526b90f597120466249ff17bb6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Aug 2022 18:06:27 +0000 Subject: [PATCH 14/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 33 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 2717 insertions(+), 5925 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 7212d81..0000000 --- a/.gitattributes +++ /dev/null @@ -1,33 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6c16aaa..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-08-01T01:44:47.971Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d15d7f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..f16eda9 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 752ac3ffb3ec7ffa9f97bdd811066f1b327b4f24 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 03:49:44 +0000 Subject: [PATCH 15/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From a7cc509371f8717785085911cba4195506c4a13b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:13:18 +0000 Subject: [PATCH 16/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d15d7f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index f16eda9..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From fcf0617c62343ce9faf3aa15fea9806a5d3c24f6 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Sep 2022 14:14:08 +0000 Subject: [PATCH 17/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 2717 insertions(+), 5941 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 0e0d3d0..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-09-01T01:45:03.987Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index e932afb..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The function does not compile if provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The function does not compile if provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The function does not compile if provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d15d7f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index 234a528..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var array = require( './main.js' ); - - -// EXPORTS // - -module.exports = array; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..b7e207c --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 6aed3baab36fe356d4df89e44b446b8341e06ab5 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 27 Sep 2022 22:50:01 +0000 Subject: [PATCH 18/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 9825e5ffd3e4a6511e00d8d7c31f1ee20c6c1b30 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Sep 2022 00:28:58 +0000 Subject: [PATCH 19/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d15d7f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index b7e207c..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 81ee8504f48c748461dd6a6698176b5e870bdbdc Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 28 Sep 2022 00:30:04 +0000 Subject: [PATCH 20/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 43 files changed, 2717 insertions(+), 5940 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d15d7f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":";;oxEA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,sECTjB,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,ECkDR,SAASK,EAAUC,EAAKR,GAEvB,MAAe,YAAVA,EAhFN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIC,IAAKN,IAEpB,OAAOD,EAuECQ,CAASF,GAEF,WAAVR,EA/DN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAsDCS,CAAQH,GA3CjB,SAAgBA,EAAKR,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,EAiCAU,CAAOJ,EAAKR,GC1FpB,SAASa,EAAaC,EAAOC,EAAOC,GACnC,IAAId,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIa,EAAMF,EAAOX,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIW,EAAOX,IACvBD,EAAIG,KAAMU,EAAOZ,IAElB,OAAOD,ECGR,SAASe,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjB,EACAkB,EACAC,EACAlB,EACAmB,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxB,QAEZQ,EAAM,GACS,cAAViB,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnB,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAMgB,GAEX,IAAMlB,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,QAEd,CACN,IAAMA,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,IAGrB,OAAOD,ECoCR,SAASsB,IACR,IAAIC,EACAP,EACApB,EACA4B,EACAP,EACAnB,EACA2B,EACAZ,EACAD,EACAc,EACAC,EACA9B,EAEA+B,EAEJ,GAA0B,IAArBC,UAAUrC,OACd,GAAKF,EAAmBuC,UAAW,IAClCjC,EAASiC,UAAW,GACpBN,EAAU,OACJ,CAEN,IAAMO,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,EAAYV,EAAS,YAEnBjC,EADNM,EAAS2B,EAAQ3B,QAEhB,MAAM,IAAImC,UAAWC,EAAQ,QAAS,SAAUpC,QAI7C,CAEN,IAAMN,EADNM,EAASiC,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASpC,IAGvC,IAAMkC,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAiBxC,GAbK3B,IACCsC,EAAetC,IACnB6B,EAAQ7B,EAAOE,MACf8B,GAAM,IAENH,EAAQU,EAASvC,GACjBgC,GAAM,IAGRF,EAAQ,GACRC,EAAO,GAGFM,EAAYV,EAAS,YAEzB,GADAI,EAAKS,QAAUb,EAAQa,SACjBC,EAAeV,EAAKS,SACzB,MAAM,IAAIL,UAAWC,EAAQ,QAAS,UAAWL,EAAKS,eAGvDT,EAAKS,QAAUE,EAEhB,GAAKL,EAAYV,EAAS,YAEzB,GADAI,EAAKY,QAAUhB,EAAQgB,SACjBC,EAAWb,EAAKY,SACrB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,UAAWL,EAAKY,eAGvDZ,EAAKY,QAAUD,EAEhB,GAAKL,EAAYV,EAAS,UAEzB,GADAI,EAAKb,MAAQS,EAAQT,OACf2B,EAAsBd,EAAKb,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASL,EAAKb,aAIrDa,EAAKb,MAAQwB,EAId,GAAKL,EAAYV,EAAS,SAAY,CAErC,GADAzB,EAAQyB,EAAQzB,OACV4C,EAAY5C,GACjB,MAAM,IAAIiC,UAAWC,EAAQ,QAAS,QAASlC,IAEhD,GAAK2B,IAAUkB,EAAelB,EAAO3B,EAAO6B,EAAKS,SAChD,MAAM,IAAIQ,MAAOZ,EAAQ,QAASL,EAAKS,QAASX,EAAO3B,SASvDA,EAPU2B,IAILG,GAAiB,YAAVH,GAGJA,EAGDa,EAET,GAAKL,EAAYV,EAAS,UAEzB,GAAe,SADfN,EAAQM,EAAQN,QACkB,SAAVA,EAClBW,EAEW,QAAVX,EAMHA,EADY,IAHP4B,EAAejD,EAAOoB,SAInBsB,EAEA1C,EAAOqB,MAIG,SAAVA,IACTA,EAAQrB,EAAOqB,OAGhBA,EAAQqB,OAEH,IAAMQ,EAAS7B,GACrB,MAAM,IAAIc,UAAWC,EAAQ,QAAS,QAASf,SAGhDA,EAAQqB,EAiBT,GAfKL,EAAYV,EAAS,QACzBG,EAAMqB,KAAOxB,EAAQwB,KAErBrB,EAAMqB,KAAOT,EAETL,EAAYV,EAAS,WACzBG,EAAMsB,QAAUzB,EAAQyB,QAExBtB,EAAMsB,QAAU,CAAEtB,EAAMqB,MAEpBd,EAAYV,EAAS,YACzBG,EAAMuB,SAAW1B,EAAQ0B,SAEzBvB,EAAMuB,SAAWX,EAEbL,EAAYV,EAAS,SAEzB,GADAI,EAAKuB,KAAO3B,EAAQ2B,MACdV,EAAWb,EAAKuB,MACrB,MAAM,IAAInB,UAAWC,EAAQ,QAAS,OAAQL,EAAKuB,YAGpDvB,EAAKuB,KAAOZ,EAGb,GAAKL,EAAYV,EAAS,SAAY,CAErC,IAAMjC,EADNuB,EAAQU,EAAQV,OAEf,MAAM,IAAIkB,UAAWC,EAAQ,QAAS,QAASnB,IAEhDD,EAAQC,EAAMrB,OACdK,EAAMsD,EAAOtC,OACP,KAAKjB,EAeX,MAAM,IAAIgD,MAAOZ,EAAQ,UAdpBJ,GACJf,EAAQjB,EAAOiB,MACfD,EAAQhB,EAAOgB,MACff,EAAMD,EAAOJ,QACFmC,EAAKY,SAAWa,EAASxD,IAEpCgB,GADAC,EAAQwC,EAAYzD,IACNJ,OACdK,EAAMsD,EAAOtC,KAEbD,EAAQ,EAERC,EAAQ,CADRhB,EAAMD,EAAOJ,SAYf,GALKoB,EAAQe,EAAKb,QACjBD,EAAQF,EAAaC,EAAOC,EAAOc,EAAKb,OACxCF,EAAQe,EAAKb,OAGTc,EAAM,CACV,GAAKhC,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,UAE1BP,IAAU3B,GAAS6B,EAAKuB,KAC5BtD,EAASS,EAAUT,EAAQE,IAE3BkB,EAAUpB,EAAOoB,QACjBQ,EAAS5B,EAAO4B,OAChB5B,EAASA,EAAO2D,KACXvC,EAAQxB,OAASoB,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,UAG5C,GAAKrB,EAAS,CAIpB,GAHe,YAAV6B,GAAuBE,EAAKY,UAChC3C,EAAS4D,EAAc5D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,WAE1BP,IAAU3B,GAAS6B,EAAKuB,QAC5BtD,EAASD,EAAYC,EAAQC,EAAKC,SAGnCF,EAAS6D,EAAc3D,EAAOD,GAO/B,YAJiB,IAAZmB,IACJA,EAAU0C,EAAe7C,EAAOI,GAChCO,EAASmC,EAAgB9C,EAAOG,IAE1B,IAAI4C,EAAS9D,EAAOF,EAAQiB,EAAOG,EAASQ,EAAQP,EAAOS"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ad2c634 --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 59111e1f58705ad917c9e19725d024e282ae53d8 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 05:02:36 +0000 Subject: [PATCH 21/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From dade7afe4a3abd817d5ee9c6e76d2377ebcd5a44 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 20:09:19 +0000 Subject: [PATCH 22/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d15d7f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ad2c634..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 4fbcc770f55cbaca25fb5222d01f106ab77daf4b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 1 Oct 2022 20:10:16 +0000 Subject: [PATCH 23/96] Auto-generated commit --- .editorconfig | 181 -- .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ------ .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 -- .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 -- .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 ---- README.md | 47 +- benchmark/benchmark.js | 1209 --------- benchmark/python/numpy/benchmark.py | 284 --- branches.md | 53 - docs/repl.txt | 159 -- docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 --- package.json | 78 +- stats.html | 2689 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 2717 insertions(+), 5941 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 6f1ce9b..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-10-01T02:12:49.835Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 29bf533..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a7a7f51..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.9.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 39b1613..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 7ca169c..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '0 8 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "::set-output name=package_name::$name" - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "::set-output name=data::$data" - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v2 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v2 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 5094681..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "::set-output name=remote-exists::true" - else - echo "::set-output name=remote-exists::false" - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v2 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "::set-output name=alias::${alias}" - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d15d7f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..6b5518f --- /dev/null +++ b/stats.html @@ -0,0 +1,2689 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From dee435fb4eb185c82829ac838dd474c7a64ec341 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 04:33:13 +0000 Subject: [PATCH 24/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 834646ef29d6df421d38113e07ea8d6609ebd081 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 19:19:42 +0000 Subject: [PATCH 25/96] Remove files --- index.d.ts | 228 ----- index.mjs | 4 - index.mjs.map | 1 - stats.html | 2689 ------------------------------------------------- 4 files changed, 2922 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d15d7f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&v(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 6b5518f..0000000 --- a/stats.html +++ /dev/null @@ -1,2689 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 916851575cbbf739e9ccfa2336160f90e70cfcbf Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 1 Nov 2022 19:20:34 +0000 Subject: [PATCH 26/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 760 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 1209 ------ benchmark/python/numpy/benchmark.py | 284 -- branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 -- package.json | 78 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 4072 insertions(+), 5941 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index dc58584..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-01T01:58:04.228Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9113bfe..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,760 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..12ab994 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.7-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":";;2xEA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,qECXA,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,CACR,CCiDA,SAASK,EAAUC,EAAKR,GAEvB,MAAe,YAAVA,EAhFN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIC,IAAKN,IAEpB,OAAOD,CACR,CAsESQ,CAASF,GAEF,WAAVR,EA/DN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,CACR,CAqDSS,CAAQH,GA3CjB,SAAgBA,EAAKR,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,CACR,CAgCQU,CAAOJ,EAAKR,EACpB,CC3FA,SAASa,EAAaC,EAAOC,EAAOC,GACnC,IAAId,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIa,EAAMF,EAAOX,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIW,EAAOX,IACvBD,EAAIG,KAAMU,EAAOZ,IAElB,OAAOD,CACR,CCEA,SAASe,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjB,EACAkB,EACAC,EACAlB,EACAmB,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxB,QAEZQ,EAAM,GACS,cAAViB,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnB,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAMgB,GAEX,IAAMlB,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,GAEpB,CACD,OAAOD,CACR,CCmCA,SAASsB,IACR,IAAIC,EACAP,EACApB,EACA4B,EACAP,EACAnB,EACA2B,EACAZ,EACAD,EACAc,EACAC,EACA9B,EAEA+B,EAEJ,GAA0B,IAArBC,UAAUrC,OACd,GAAKF,EAAmBuC,UAAW,IAClCjC,EAASiC,UAAW,GACpBN,EAAU,CAAA,MACJ,CAEN,IAAMO,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,EAAYV,EAAS,YAEnBjC,EADNM,EAAS2B,EAAQ3B,QAEhB,MAAM,IAAImC,UAAWC,EAAQ,QAAS,SAAUpC,GAGlD,KACK,CAEN,IAAMN,EADNM,EAASiC,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASpC,IAGvC,IAAMkC,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,GAGvC,CAcD,GAbK3B,IACCsC,EAAetC,IACnB6B,EAAQ7B,EAAOE,MACf8B,GAAM,IAENH,EAAQU,EAASvC,GACjBgC,GAAM,IAGRF,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFM,EAAYV,EAAS,YAEzB,GADAI,EAAKS,QAAUb,EAAQa,SACjBC,EAAeV,EAAKS,SACzB,MAAM,IAAIL,UAAWC,EAAQ,QAAS,UAAWL,EAAKS,eAGvDT,EAAKS,QAAUE,EAEhB,GAAKL,EAAYV,EAAS,YAEzB,GADAI,EAAKY,QAAUhB,EAAQgB,SACjBC,EAAWb,EAAKY,SACrB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,UAAWL,EAAKY,eAGvDZ,EAAKY,QAAUD,EAEhB,GAAKL,EAAYV,EAAS,UAEzB,GADAI,EAAKb,MAAQS,EAAQT,OACf2B,EAAsBd,EAAKb,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASL,EAAKb,aAIrDa,EAAKb,MAAQwB,EAId,GAAKL,EAAYV,EAAS,SAAY,CAErC,GADAzB,EAAQyB,EAAQzB,OACV4C,EAAY5C,GACjB,MAAM,IAAIiC,UAAWC,EAAQ,QAAS,QAASlC,IAEhD,GAAK2B,IAAUkB,EAAelB,EAAO3B,EAAO6B,EAAKS,SAChD,MAAM,IAAIQ,MAAOZ,EAAQ,QAASL,EAAKS,QAASX,EAAO3B,GAExD,MAOCA,EAPU2B,IAILG,GAAiB,YAAVH,GAGJA,EAGDa,EAET,GAAKL,EAAYV,EAAS,UAEzB,GAAe,SADfN,EAAQM,EAAQN,QACkB,SAAVA,EAClBW,EAEW,QAAVX,EAMHA,EADY,IAHP4B,EAAejD,EAAOoB,SAInBsB,EAEA1C,EAAOqB,MAIG,SAAVA,IACTA,EAAQrB,EAAOqB,OAGhBA,EAAQqB,OAEH,IAAMQ,EAAS7B,GACrB,MAAM,IAAIc,UAAWC,EAAQ,QAAS,QAASf,SAGhDA,EAAQqB,EAiBT,GAfKL,EAAYV,EAAS,QACzBG,EAAMqB,KAAOxB,EAAQwB,KAErBrB,EAAMqB,KAAOT,EAETL,EAAYV,EAAS,WACzBG,EAAMsB,QAAUzB,EAAQyB,QAExBtB,EAAMsB,QAAU,CAAEtB,EAAMqB,MAEpBd,EAAYV,EAAS,YACzBG,EAAMuB,SAAW1B,EAAQ0B,SAEzBvB,EAAMuB,SAAWX,EAEbL,EAAYV,EAAS,SAEzB,GADAI,EAAKuB,KAAO3B,EAAQ2B,MACdV,EAAWb,EAAKuB,MACrB,MAAM,IAAInB,UAAWC,EAAQ,QAAS,OAAQL,EAAKuB,YAGpDvB,EAAKuB,KAAOZ,EAGb,GAAKL,EAAYV,EAAS,SAAY,CAErC,IAAMjC,EADNuB,EAAQU,EAAQV,OAEf,MAAM,IAAIkB,UAAWC,EAAQ,QAAS,QAASnB,IAEhDD,EAAQC,EAAMrB,OACdK,EAAMsD,EAAOtC,EACb,KAAM,KAAKjB,EAeX,MAAM,IAAIgD,MAAOZ,EAAQ,UAdpBJ,GACJf,EAAQjB,EAAOiB,MACfD,EAAQhB,EAAOgB,MACff,EAAMD,EAAOJ,QACFmC,EAAKY,SAAWa,EAASxD,IAEpCgB,GADAC,EAAQwC,EAAYzD,IACNJ,OACdK,EAAMsD,EAAOtC,KAEbD,EAAQ,EAERC,EAAQ,CADRhB,EAAMD,EAAOJ,QAKd,CAOD,GALKoB,EAAQe,EAAKb,QACjBD,EAAQF,EAAaC,EAAOC,EAAOc,EAAKb,OACxCF,EAAQe,EAAKb,OAGTc,EAAM,CACV,GAAKhC,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,UAE1BP,IAAU3B,GAAS6B,EAAKuB,KAC5BtD,EAASS,EAAUT,EAAQE,IAE3BkB,EAAUpB,EAAOoB,QACjBQ,EAAS5B,EAAO4B,OAChB5B,EAASA,EAAO2D,KACXvC,EAAQxB,OAASoB,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,IAGlD,MAAM,GAAKrB,EAAS,CAIpB,GAHe,YAAV6B,GAAuBE,EAAKY,UAChC3C,EAAS4D,EAAc5D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,WAE1BP,IAAU3B,GAAS6B,EAAKuB,QAC5BtD,EAASD,EAAYC,EAAQC,EAAKC,GAErC,MACEF,EAAS6D,EAAc3D,EAAOD,GAO/B,YAJiB,IAAZmB,IACJA,EAAU0C,EAAe7C,EAAOI,GAChCO,EAASmC,EAAgB9C,EAAOG,IAE1B,IAAI4C,EAAS9D,EAAOF,EAAQiB,EAAOG,EAASQ,EAAQP,EAAOS,EACnE"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..7f44b30 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 7edae1173407b5483373a7d9789642dac911eb67 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 00:42:22 +0000 Subject: [PATCH 27/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 68331d4..55a7c23 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 8787278219878d33304b7187b3eb004b8482e970 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 14:43:03 +0000 Subject: [PATCH 28/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4277 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 12ab994..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.7-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 7f44b30..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From 2befa27ebface63d6e4d1ac1d2a8e4e99af9a2d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 4 Nov 2022 14:43:58 +0000 Subject: [PATCH 29/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 178 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 1209 ------ benchmark/python/numpy/benchmark.py | 284 -- branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 -- package.json | 78 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 4072 insertions(+), 5962 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 3ef8995..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-11-03T23:00:25.636Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9e9077d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 55a7c23..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-spec": "5.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d6e0eb4 --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From bfe3fc1d55bd168f7d97fd91b30a4f4d0600572c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 04:40:57 +0000 Subject: [PATCH 30/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 600237a..23e1382 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 7a95e0294bbadf368aad8ffbeb9f19f6e54b14ee Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:45:03 +0000 Subject: [PATCH 31/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4277 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9e9077d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors' ;\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property' ;\nimport isObject from '@stdlib/assert-is-plain-object' ;\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean' ;\nimport isArray from '@stdlib/assert-is-array' ;\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer' ;\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like' ;\nimport shape2strides from '@stdlib/ndarray-base-shape2strides' ;\nimport strides2offset from '@stdlib/ndarray-base-strides2offset' ;\nimport strides2order from '@stdlib/ndarray-base-strides2order' ;\nimport numel from '@stdlib/ndarray-base-numel' ;\nimport ndarray from '@stdlib/ndarray-ctor' ;\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type' ;\nimport isOrder from '@stdlib/ndarray-base-assert-is-order' ;\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode' ;\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ;\nimport createBuffer from '@stdlib/ndarray-base-buffer' ;\nimport getType from '@stdlib/ndarray-base-buffer-dtype' ;\nimport arrayShape from '@stdlib/array-shape' ;\nimport flattenArray from '@stdlib/utils-flatten-array' ;\nimport format from '@stdlib/error-tools-fmtprodmsg' ;\nimport isArrayLikeObject from './is_array_like_object.js' ;\nimport defaults from './defaults.json' ;\nimport castBuffer from './cast_buffer.js' ;\nimport copyView from './copy_view.js' ;\nimport expandShape from './expand_shape.js' ;\nimport expandStrides from './expand_strides.js' ;\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d6e0eb4..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From a7194d33bb2f9ff086b2a6e73bfa8ff48870e29c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 1 Dec 2022 15:46:00 +0000 Subject: [PATCH 32/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 781 ---- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 183 - .npmignore | 227 -- .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 47 +- benchmark/benchmark.js | 1209 ------ benchmark/python/numpy/benchmark.py | 284 -- branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 -- package.json | 78 +- stats.html | 4044 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 4072 insertions(+), 5967 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index cec4cf1..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2022-12-01T02:48:53.391Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 37ddb4f..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,781 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2022. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..9e9077d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport defaults from './defaults.json';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './expand_strides.js';\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 23e1382..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "2.x.x" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..156c64f --- /dev/null +++ b/stats.html @@ -0,0 +1,4044 @@ + + + + + + + + RollUp Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 104d17b6fa5e21f2ff9f7de5777b9c95602441d2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 04:14:35 +0000 Subject: [PATCH 33/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index cadaf41..14b14af 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var defaults = require( './defaults.json' ); var castBuffer = require( './cast_buffer.js' ); @@ -128,23 +128,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -164,7 +164,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -172,7 +172,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -180,7 +180,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -191,10 +191,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -232,7 +232,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -255,7 +255,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -264,7 +264,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -283,7 +283,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -293,7 +293,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -311,7 +311,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 5ab5e65..a017c7b 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@stdlib/ndarray-base-strides2offset": "^0.0.x", "@stdlib/ndarray-base-strides2order": "^0.0.x", "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/string-format": "^0.0.x", + "@stdlib/error-tools-fmtprodmsg": "^0.0.x", "@stdlib/types": "^0.0.x", "@stdlib/utils-flatten-array": "^0.0.x" }, From 9b7e6ad97a93b635e0e7f8deab07b2c237af897a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 15:59:22 +0000 Subject: [PATCH 34/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4044 ------------------------------------------------- 4 files changed, 4277 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 9e9077d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2022 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport defaults from './defaults.json';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './expand_strides.js';\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 156c64f..0000000 --- a/stats.html +++ /dev/null @@ -1,4044 +0,0 @@ - - - - - - - - RollUp Visualizer - - - -
- - - - - From bfc26d3c39eef7c16dd54f3f6a088d3c476711e2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Wed, 1 Feb 2023 16:00:16 +0000 Subject: [PATCH 35/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 791 --- .github/workflows/publish.yml | 117 - .github/workflows/test.yml | 92 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 184 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.json | 10 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 333 -- package.json | 78 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 126 - 44 files changed, 6205 insertions(+), 5978 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.json delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2e4bfd9..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2023-02-01T02:29:25.025Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4eea88..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,791 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\"/\"@stdlib\/error-tools-fmtprodmsg\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^0.0.x'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5fe5731..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..0608876 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport defaults from './defaults.json';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './expand_strides.js';\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":";;2xEA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,qECXA,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,CACR,CCiDA,SAASK,EAAUC,EAAKR,GAEvB,MAAe,YAAVA,EAhFN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIC,IAAKN,IAEpB,OAAOD,CACR,CAsESQ,CAASF,GAEF,WAAVR,EA/DN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,CACR,CAqDSS,CAAQH,GA3CjB,SAAgBA,EAAKR,GACpB,IACID,EACAG,EACAC,EAKJ,IADAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,QAEJS,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIC,IAAKN,GAErB,OAAOD,CACR,CAgCQU,CAAOJ,EAAKR,EACpB,CC3FA,SAASa,EAAaC,EAAOC,EAAOC,GACnC,IAAId,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIa,EAAMF,EAAOX,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIW,EAAOX,IACvBD,EAAIG,KAAMU,EAAOZ,IAElB,OAAOD,CACR,CCEA,SAASe,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjB,EACAkB,EACAC,EACAlB,EACAmB,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxB,QAEZQ,EAAM,GACS,cAAViB,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnB,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAMgB,GAEX,IAAMlB,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAImB,EAAGnB,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiB,EAAGjB,IACnBD,EAAIG,KAAMa,EAASf,GAEpB,CACD,OAAOD,CACR,CCmCA,SAASsB,IACR,IAAIC,EACAP,EACApB,EACA4B,EACAP,EACAnB,EACA2B,EACAZ,EACAD,EACAc,EACAC,EACA9B,EAEA+B,EAEJ,GAA0B,IAArBC,UAAUrC,OACd,GAAKF,EAAmBuC,UAAW,IAClCjC,EAASiC,UAAW,GACpBN,EAAU,CAAA,MACJ,CAEN,IAAMO,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,IAEvC,GAAKU,EAAYV,EAAS,YAEnBjC,EADNM,EAAS2B,EAAQ3B,QAEhB,MAAM,IAAImC,UAAWC,EAAQ,QAAS,SAAUpC,GAGlD,KACK,CAEN,IAAMN,EADNM,EAASiC,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASpC,IAGvC,IAAMkC,EADNP,EAAUM,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAAST,GAGvC,CAcD,GAbK3B,IACCsC,EAAetC,IACnB6B,EAAQ7B,EAAOE,MACf8B,GAAM,IAENH,EAAQU,EAASvC,GACjBgC,GAAM,IAGRF,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFM,EAAYV,EAAS,YAEzB,GADAI,EAAKS,QAAUb,EAAQa,SACjBC,EAAeV,EAAKS,SACzB,MAAM,IAAIL,UAAWC,EAAQ,QAAS,UAAWL,EAAKS,eAGvDT,EAAKS,QAAUE,EAEhB,GAAKL,EAAYV,EAAS,YAEzB,GADAI,EAAKY,QAAUhB,EAAQgB,SACjBC,EAAWb,EAAKY,SACrB,MAAM,IAAIR,UAAWC,EAAQ,QAAS,UAAWL,EAAKY,eAGvDZ,EAAKY,QAAUD,EAEhB,GAAKL,EAAYV,EAAS,UAEzB,GADAI,EAAKb,MAAQS,EAAQT,OACf2B,EAAsBd,EAAKb,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASL,EAAKb,aAIrDa,EAAKb,MAAQwB,EAId,GAAKL,EAAYV,EAAS,SAAY,CAErC,GADAzB,EAAQyB,EAAQzB,OACV4C,EAAY5C,GACjB,MAAM,IAAIiC,UAAWC,EAAQ,QAAS,QAASlC,IAEhD,GAAK2B,IAAUkB,EAAelB,EAAO3B,EAAO6B,EAAKS,SAChD,MAAM,IAAIQ,MAAOZ,EAAQ,QAASL,EAAKS,QAASX,EAAO3B,GAExD,MAOCA,EAPU2B,IAILG,GAAiB,YAAVH,GAGJA,EAGDa,EAET,GAAKL,EAAYV,EAAS,UAEzB,GAAe,SADfN,EAAQM,EAAQN,QACkB,SAAVA,EAClBW,EAEW,QAAVX,EAMHA,EADY,IAHP4B,EAAejD,EAAOoB,SAInBsB,EAEA1C,EAAOqB,MAIG,SAAVA,IACTA,EAAQrB,EAAOqB,OAGhBA,EAAQqB,OAEH,IAAMQ,EAAS7B,GACrB,MAAM,IAAIc,UAAWC,EAAQ,QAAS,QAASf,SAGhDA,EAAQqB,EAiBT,GAfKL,EAAYV,EAAS,QACzBG,EAAMqB,KAAOxB,EAAQwB,KAErBrB,EAAMqB,KAAOT,EAETL,EAAYV,EAAS,WACzBG,EAAMsB,QAAUzB,EAAQyB,QAExBtB,EAAMsB,QAAU,CAAEtB,EAAMqB,MAEpBd,EAAYV,EAAS,YACzBG,EAAMuB,SAAW1B,EAAQ0B,SAEzBvB,EAAMuB,SAAWX,EAEbL,EAAYV,EAAS,SAEzB,GADAI,EAAKuB,KAAO3B,EAAQ2B,MACdV,EAAWb,EAAKuB,MACrB,MAAM,IAAInB,UAAWC,EAAQ,QAAS,OAAQL,EAAKuB,YAGpDvB,EAAKuB,KAAOZ,EAGb,GAAKL,EAAYV,EAAS,SAAY,CAErC,IAAMjC,EADNuB,EAAQU,EAAQV,OAEf,MAAM,IAAIkB,UAAWC,EAAQ,QAAS,QAASnB,IAEhDD,EAAQC,EAAMrB,OACdK,EAAMsD,EAAOtC,EACb,KAAM,KAAKjB,EAeX,MAAM,IAAIgD,MAAOZ,EAAQ,UAdpBJ,GACJf,EAAQjB,EAAOiB,MACfD,EAAQhB,EAAOgB,MACff,EAAMD,EAAOJ,QACFmC,EAAKY,SAAWa,EAASxD,IAEpCgB,GADAC,EAAQwC,EAAYzD,IACNJ,OACdK,EAAMsD,EAAOtC,KAEbD,EAAQ,EAERC,EAAQ,CADRhB,EAAMD,EAAOJ,QAKd,CAOD,GALKoB,EAAQe,EAAKb,QACjBD,EAAQF,EAAaC,EAAOC,EAAOc,EAAKb,OACxCF,EAAQe,EAAKb,OAGTc,EAAM,CACV,GAAKhC,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,UAE1BP,IAAU3B,GAAS6B,EAAKuB,KAC5BtD,EAASS,EAAUT,EAAQE,IAE3BkB,EAAUpB,EAAOoB,QACjBQ,EAAS5B,EAAO4B,OAChB5B,EAASA,EAAO2D,KACXvC,EAAQxB,OAASoB,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,IAGlD,MAAM,GAAKrB,EAAS,CAIpB,GAHe,YAAV6B,GAAuBE,EAAKY,UAChC3C,EAAS4D,EAAc5D,IAEnBA,EAAOJ,SAAWK,EACtB,MAAM,IAAIyD,WAAYtB,EAAQ,WAE1BP,IAAU3B,GAAS6B,EAAKuB,QAC5BtD,EAASD,EAAYC,EAAQC,EAAKC,GAErC,MACEF,EAAS6D,EAAc3D,EAAOD,GAO/B,YAJiB,IAAZmB,IACJA,EAAU0C,EAAe7C,EAAOI,GAChCO,EAASmC,EAAgB9C,EAAOG,IAE1B,IAAI4C,EAAS9D,EAAOF,EAAQiB,EAAOG,EAASQ,EAAQP,EAAOS,EACnE"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.json b/lib/defaults.json deleted file mode 100644 index 41de529..0000000 --- a/lib/defaults.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "casting": "safe", - "copy": false, - "dtype": "float64", - "flatten": true, - "mode": "throw", - "ndmin": 0, - "order": "row-major", - "readonly": false -} diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 14b14af..0000000 --- a/lib/main.js +++ /dev/null @@ -1,333 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var defaults = require( './defaults.json' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index a017c7b..2f3ab7a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,56 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.x", - "@stdlib/assert-has-own-property": "^0.0.x", - "@stdlib/assert-is-array": "^0.0.x", - "@stdlib/assert-is-boolean": "^0.0.x", - "@stdlib/assert-is-ndarray-like": "^0.0.x", - "@stdlib/assert-is-nonnegative-integer": "^0.0.x", - "@stdlib/assert-is-plain-object": "^0.0.x", - "@stdlib/buffer-alloc-unsafe": "^0.0.x", - "@stdlib/constants-float64-pinf": "^0.0.x", - "@stdlib/math-base-assert-is-integer": "^0.0.x", - "@stdlib/math-base-special-abs": "^0.0.x", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.x", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.x", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.x", - "@stdlib/ndarray-base-assert-is-order": "^0.0.x", - "@stdlib/ndarray-base-buffer": "^0.0.x", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.x", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.x", - "@stdlib/ndarray-base-numel": "^0.0.x", - "@stdlib/ndarray-base-shape2strides": "^0.0.x", - "@stdlib/ndarray-base-strides2offset": "^0.0.x", - "@stdlib/ndarray-base-strides2order": "^0.0.x", - "@stdlib/ndarray-ctor": "^0.0.x", - "@stdlib/error-tools-fmtprodmsg": "^0.0.x", - "@stdlib/types": "^0.0.x", - "@stdlib/utils-flatten-array": "^0.0.x" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.x", - "@stdlib/bench": "^0.0.x", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -101,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "patreon", "url": "https://www.patreon.com/athan" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1c1d4a8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 8da98e2c00ec764d7eae9a74470ddb33c8d6cb20 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Apr 2023 01:23:48 +0000 Subject: [PATCH 36/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 6ad0fb2..12e2a89 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -133,23 +133,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -169,7 +169,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -177,7 +177,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -185,7 +185,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -196,10 +196,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -237,7 +237,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -260,7 +260,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -269,7 +269,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -288,7 +288,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -298,7 +298,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -316,7 +316,7 @@ function array() { buffer = flattenArray( buffer ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 946c211..f641691 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "@stdlib/ndarray-base-strides2order": "^0.0.6", "@stdlib/ndarray-ctor": "^0.0.10", "@stdlib/ndarray-defaults": "github:stdlib-js/ndarray-defaults#main", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14", "@stdlib/utils-flatten-array": "^0.0.7" }, From 04bc91c3ee461c461ffc2849af2b52aa45fc728a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Apr 2023 01:24:46 +0000 Subject: [PATCH 37/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 0608876..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function T(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport defaults from './defaults.json';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './expand_strides.js';\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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","casting","isCastingMode","defaults","flatten","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","mode","submode","readonly","copy","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1c1d4a8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From bc80e98466d8d00069ce986bef2d5beca247350f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 2 Apr 2023 01:26:26 +0000 Subject: [PATCH 38/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 338 -- package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 126 - 43 files changed, 6205 insertions(+), 6168 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..ba85913 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function R(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 12e2a89..0000000 --- a/lib/main.js +++ /dev/null @@ -1,338 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flattenArray = require( '@stdlib/utils-flatten-array' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flattenArray( buffer ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index f641691..a62794c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-shape": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/buffer-alloc-unsafe": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/math-base-assert-is-integer": "^0.0.7", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.9", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.8", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.6", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.6", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^0.0.8", - "@stdlib/ndarray-base-strides2order": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/ndarray-defaults": "github:stdlib-js/ndarray-defaults#main", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14", - "@stdlib/utils-flatten-array": "^0.0.7" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -102,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..18e3a27 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 62daba024670f70593403b72648ecbc8b1d94059 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 21 Jul 2023 22:34:50 +0000 Subject: [PATCH 39/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index a16aa13..61e3832 100644 --- a/lib/main.js +++ b/lib/main.js @@ -39,7 +39,7 @@ var createBuffer = require( '@stdlib/ndarray-base-buffer' ); var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -134,23 +134,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le5K', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0Le5M', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0Le2h', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -170,7 +170,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -178,7 +178,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -186,7 +186,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -197,10 +197,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -238,7 +238,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0Le5Q', 'order', order ) ); } } else { order = defaults.order; @@ -261,7 +261,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -270,7 +270,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0Le5R', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -290,7 +290,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format( '0Le0X' ) ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -300,7 +300,7 @@ function array() { // 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... if ( FLG ) { if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -318,7 +318,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), false ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format( '0Le0Y' ) ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 3e43e18..1d45eae 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,7 @@ "@stdlib/ndarray-base-strides2order": "^0.0.6", "@stdlib/ndarray-ctor": "^0.0.10", "@stdlib/ndarray-defaults": "github:stdlib-js/ndarray-defaults#main", - "@stdlib/string-format": "^0.0.3", + "@stdlib/error-tools-fmtprodmsg": "^0.0.2", "@stdlib/types": "^0.0.14" }, "devDependencies": { From 323f9b26ac8c50e1602bfe0d1ccc05ce2e82dd3c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 21 Jul 2023 22:35:21 +0000 Subject: [PATCH 40/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index ba85913..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/utils-flatten-array@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function R(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flattenArray from '@stdlib/utils-flatten-array';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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 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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\n\t\t} else if ( opts.flatten && isArray( buffer ) ) {\n\t\t\tshape = arrayShape( buffer );\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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 = flattenArray( buffer );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","data","flattenArray","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 18e3a27..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From c6bb820549d8d3664f15dbf97f187584e5faea0a Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 21 Jul 2023 22:36:44 +0000 Subject: [PATCH 41/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 62 - .github/workflows/cancel.yml | 56 - .github/workflows/close_pull_requests.yml | 44 - .github/workflows/examples.yml | 62 - .github/workflows/npm_downloads.yml | 108 - .github/workflows/productionize.yml | 798 --- .github/workflows/publish.yml | 242 - .github/workflows/test.yml | 97 - .github/workflows/test_bundles.yml | 180 - .github/workflows/test_coverage.yml | 123 - .github/workflows/test_install.yml | 83 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - docs/repl.txt | 159 - docs/types/test.ts | 257 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 340 -- package.json | 79 +- stats.html | 6177 +++++++++++++++++++++ test/test.js | 126 - 43 files changed, 6205 insertions(+), 6170 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0fd4d6c..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 06a9a75..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index a00dbe5..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,56 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - uses: styfle/cancel-workflow-action@0.11.0 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index 8c91e89..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,44 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - run: - runs-on: ubuntu-latest - steps: - - uses: superbrothers/close-pull-request@v3 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 7902a7d..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,62 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout the repository' - uses: actions/checkout@v3 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 3d4e9d3..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,108 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - uses: actions/upload-artifact@v3 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - uses: distributhor/workflow-webhook@v3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 3e8e2db..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,798 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - uses: actions/checkout@v3 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Format error messages: - - name: 'Replace double quotes with single quotes in rewritten format string error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\( \"([a-zA-Z0-9]+)\"/Error\( format\( '\1'/g" {} \; - - # Format string literal error messages: - - name: 'Replace double quotes with single quotes in rewritten string literal error messages' - run: | - find . -name "*.js" -exec sed -E -i "s/Error\( format\(\"([a-zA-Z0-9]+)\"\)/Error\( format\( '\1' \)/g" {} \; - - # Format code: - - name: 'Replace double quotes with single quotes in inserted `require` calls' - run: | - find . -name "*.js" -exec sed -E -i "s/require\( ?\"@stdlib\/error-tools-fmtprodmsg\" ?\);/require\( '@stdlib\/error-tools-fmtprodmsg' \);/g" {} \; - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/checkout@v3 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - uses: act10ns/slack@v1 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - uses: actions/checkout@v3 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - uses: actions/setup-node@v3 - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -288,7 +281,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -348,17 +341,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index 042a95c..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,257 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType ndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType ndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType ndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 996b87c..abb46f6 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 2.0 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..20fc829 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function R(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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( format( '0Le0Y' ) );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","data","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 61e3832..0000000 --- a/lib/main.js +++ /dev/null @@ -1,340 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getType = require( '@stdlib/ndarray-base-buffer-dtype' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le5K', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5L', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0Le5M', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0Le2h', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = buffer.dtype; - FLG = true; - } else { - btype = getType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0Le5N', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0Le30', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0Le35', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0Le5O', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0Le5P', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( buffer.strides ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = buffer.order; - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = buffer.order; - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0Le5Q', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0Le30', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0Le5R', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = buffer.shape; - ndims = buffer.ndims; - len = buffer.length; - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format( '0Le0X' ) ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = buffer.strides; - offset = buffer.offset; - buffer = buffer.data; - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), false ); - } - if ( buffer.length !== len ) { - throw new RangeError( format( '0Le0Y' ) ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 1d45eae..a62794c 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.0.9", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,57 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-flatten": "github:stdlib-js/array-base-flatten#main", - "@stdlib/array-shape": "^0.0.6", - "@stdlib/assert-has-own-property": "^0.0.7", - "@stdlib/assert-is-array": "^0.0.7", - "@stdlib/assert-is-boolean": "^0.0.8", - "@stdlib/assert-is-ndarray-like": "^0.0.6", - "@stdlib/assert-is-nonnegative-integer": "^0.0.7", - "@stdlib/assert-is-plain-object": "^0.0.7", - "@stdlib/buffer-alloc-unsafe": "^0.0.7", - "@stdlib/constants-float64-pinf": "^0.0.8", - "@stdlib/math-base-assert-is-integer": "^0.0.7", - "@stdlib/math-base-special-abs": "^0.0.6", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.0.9", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.0.7", - "@stdlib/ndarray-base-assert-is-data-type": "^0.0.8", - "@stdlib/ndarray-base-assert-is-order": "^0.0.7", - "@stdlib/ndarray-base-buffer": "^0.0.6", - "@stdlib/ndarray-base-buffer-ctors": "^0.0.6", - "@stdlib/ndarray-base-buffer-dtype": "^0.0.6", - "@stdlib/ndarray-base-numel": "^0.0.8", - "@stdlib/ndarray-base-shape2strides": "^0.0.8", - "@stdlib/ndarray-base-strides2offset": "^0.0.8", - "@stdlib/ndarray-base-strides2order": "^0.0.6", - "@stdlib/ndarray-ctor": "^0.0.10", - "@stdlib/ndarray-defaults": "github:stdlib-js/ndarray-defaults#main", - "@stdlib/error-tools-fmtprodmsg": "^0.0.2", - "@stdlib/types": "^0.0.14" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.0.6", - "@stdlib/bench": "^0.0.12", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -102,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..3e94dea --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 86c8fa0991da7d79e03c896e4cb0e50aff3f3712 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 06:10:48 +0000 Subject: [PATCH 42/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4e9d59c..089221f 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 517d95f8a15ede4a63c807dd9c51f15486aabbd9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 07:12:33 +0000 Subject: [PATCH 43/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index abb46f6..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 2.0 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, ndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): ndarray; // tslint:disable-line:max-line-length - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): ndarray; // tslint:disable-line:max-line-length - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 20fc829..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.0.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.0.8-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import L from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function R(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&w(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getType from '@stdlib/ndarray-base-buffer-dtype';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0Le5K', 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( '0Le5L', '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( '0Le5M', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0Le2h', 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 = buffer.dtype;\n\t\t\tFLG = true;\n\t\t} else {\n\t\t\tbtype = getType( 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( '0Le5N', '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( '0Le30', '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( '0Le35', '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( '0Le5O', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0Le5P', 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( buffer.strides );\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 = buffer.order;\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 = buffer.order;\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( '0Le5Q', '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( '0Le30', '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( '0Le5R', '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 = buffer.shape;\n\t\t\tndims = buffer.ndims;\n\t\t\tlen = buffer.length;\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( format( '0Le0X' ) );\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 ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format( '0Le0Y' ) );\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 = buffer.strides;\n\t\t\toffset = buffer.offset;\n\t\t\tbuffer = buffer.data;\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( format( '0Le0Y' ) );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","data","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 3e94dea..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fdd545f2004fdd39aedd100e14ec3fbcac194635 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 10 Oct 2023 07:13:53 +0000 Subject: [PATCH 44/96] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 159 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 85 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 126 - test/test.js | 126 - 48 files changed, 6205 insertions(+), 6426 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b52cf6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -299,7 +292,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -359,17 +352,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 61feb96..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var E=g(function(De,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": "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", - "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"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 25c7ccf..4244f2d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..8614774 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function M(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getDType","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","getStrides","getOrder","isOrder","submode","numel","getShape","isArray","arrayShape","RangeError","getOffset","getData","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b8e45b7..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), false ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 089221f..8cc7ef6 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-flatten": "^0.1.0", - "@stdlib/array-shape": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/buffer-alloc-unsafe": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/math-base-assert-is-integer": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.0", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@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-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^0.1.1", - "@stdlib/ndarray-base-strides2order": "^0.1.0", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-data-buffer": "github:stdlib-js/ndarray-data-buffer#main", - "@stdlib/ndarray-defaults": "^0.1.1", - "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/ndarray-offset": "github:stdlib-js/ndarray-offset#main", - "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", - "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", - "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -108,7 +28,6 @@ "dims", "numpy.array" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..9522c0f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index 5ccb991..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From e433368664fbbf8c3101a1edd8d456740297e535 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 13 Oct 2023 03:15:59 +0000 Subject: [PATCH 45/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 625db17..ff9eed2 100644 --- a/package.json +++ b/package.json @@ -68,7 +68,7 @@ "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 984a2baef0dbe54bf894381c65695e11eaba1407 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 13 Oct 2023 03:16:39 +0000 Subject: [PATCH 46/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4244f2d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; // tslint:disable-line:no-unnecessary-generics - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; // tslint:disable-line:no-unnecessary-generics - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 8614774..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.0-esm/index.mjs";function M(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getDType","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","getStrides","getOrder","isOrder","submode","numel","getShape","isArray","arrayShape","RangeError","getOffset","getData","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 9522c0f..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From eb5d3260ffdeb5909cc44493ecdc3f43c5ea8c52 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 13 Oct 2023 03:17:48 +0000 Subject: [PATCH 47/96] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 159 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 128 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 85 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 48 files changed, 6205 insertions(+), 6333 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b52cf6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -299,7 +292,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -359,17 +352,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 902c17b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var E=g(function(De,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": "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", - "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"] -} diff --git a/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 25c7ccf..4244f2d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d3c4e9d --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function M(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getDType","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","getStrides","getOrder","isOrder","submode","numel","getShape","isArray","arrayShape","RangeError","getOffset","getData","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index b5dd747..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,128 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// FUNCTIONS // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.get( i ) ); // FIXME: what if `arr` has more than one dimensions? - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - 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? - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -function typed( arr, dtype ) { - var ctor; - var len; - var out; - 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? - } - return out; -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - // TODO: handle complex number dtypes!! - if ( dtype === 'generic') { - return generic( arr ); - } - if ( dtype === 'binary' ) { - return binary( arr ); - } - return typed( arr, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b8e45b7..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), false ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index ff9eed2..bda3e50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,63 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-flatten": "^0.1.0", - "@stdlib/array-shape": "^0.1.0", - "@stdlib/assert-has-own-property": "^0.1.1", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@stdlib/assert-is-nonnegative-integer": "^0.1.0", - "@stdlib/assert-is-plain-object": "^0.1.1", - "@stdlib/buffer-alloc-unsafe": "^0.1.0", - "@stdlib/constants-float64-pinf": "^0.1.1", - "@stdlib/math-base-assert-is-integer": "^0.1.1", - "@stdlib/math-base-special-abs": "^0.1.1", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@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-numel": "^0.1.1", - "@stdlib/ndarray-base-shape2strides": "^0.1.1", - "@stdlib/ndarray-base-strides2offset": "^0.1.1", - "@stdlib/ndarray-base-strides2order": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-data-buffer": "github:stdlib-js/ndarray-data-buffer#main", - "@stdlib/ndarray-defaults": "^0.1.1", - "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/ndarray-offset": "github:stdlib-js/ndarray-offset#main", - "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", - "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", - "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -109,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5c5ebd3 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 13c56875639681dbfdcdf9faa53c657f26d6aca4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 00:50:20 +0000 Subject: [PATCH 48/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb41c67..bb6efbc 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From 31c2aece6a1930f94a1ce3b7512d00a0e733501f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 00:50:58 +0000 Subject: [PATCH 49/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4244f2d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; // tslint:disable-line:no-unnecessary-generics - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; // tslint:disable-line:no-unnecessary-generics - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d3c4e9d..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function M(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","get","generic","binary","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getDType","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","getStrides","getOrder","isOrder","submode","numel","getShape","isArray","arrayShape","RangeError","getOffset","getData","createBuffer","shape2strides","strides2offset","ndarray"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 5c5ebd3..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ec58933044885b5747ec58788fefb4be5d84b753 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 00:52:19 +0000 Subject: [PATCH 50/96] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 159 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 89 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 48 files changed, 6205 insertions(+), 6376 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b52cf6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -299,7 +292,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -359,17 +352,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e75cb6a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index d51f483..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,159 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 25c7ccf..4244f2d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a6094f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b8e45b7..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), false ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index bb6efbc..bda3e50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,67 +13,6 @@ "bugs": { "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", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@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", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@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", - "@stdlib/ndarray-base-strides2order": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-data-buffer": "github:stdlib-js/ndarray-data-buffer#main", - "@stdlib/ndarray-defaults": "^0.1.1", - "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/ndarray-offset": "github:stdlib-js/ndarray-offset#main", - "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", - "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", - "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -113,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..c1e9902 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 523051ab561c94397f1b63cb76026035e3679bfe Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 10:27:08 +0000 Subject: [PATCH 51/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cb41c67..bb6efbc 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.1.0" }, "devDependencies": { From ba5241c03824fd9a3e40fb9421e3df82b5d039c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 11:07:24 +0000 Subject: [PATCH 52/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4244f2d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; // tslint:disable-line:no-unnecessary-generics - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; // tslint:disable-line:no-unnecessary-generics - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a6094f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index c1e9902..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 832821e61697b3d28808d5dd01fdb4ef056f4373 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sat, 14 Oct 2023 11:08:31 +0000 Subject: [PATCH 53/96] Auto-generated commit --- .editorconfig | 186 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 247 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 227 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 161 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 89 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 48 files changed, 6205 insertions(+), 6378 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 13e9c39..0000000 --- a/.editorconfig +++ /dev/null @@ -1,186 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tslint.json` files: -[tslint.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index ab56cca..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c1c45e7..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 2b52cf6..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA corresponding to v3.0.3: - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 265afda..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA corresponding to v4.1.0 - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 16 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -300,7 +293,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -360,17 +353,17 @@ Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index a09e942..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index e75cb6a..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index 8cb943d..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,161 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index 25c7ccf..4244f2d 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..a6094f6 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index b8e45b7..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), false ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index bb6efbc..bda3e50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,67 +13,6 @@ "bugs": { "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", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@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", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@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", - "@stdlib/ndarray-base-strides2order": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-data-buffer": "github:stdlib-js/ndarray-data-buffer#main", - "@stdlib/ndarray-defaults": "^0.1.1", - "@stdlib/ndarray-dtype": "github:stdlib-js/ndarray-dtype#main", - "@stdlib/ndarray-offset": "github:stdlib-js/ndarray-offset#main", - "@stdlib/ndarray-order": "github:stdlib-js/ndarray-order#main", - "@stdlib/ndarray-shape": "github:stdlib-js/ndarray-shape#main", - "@stdlib/ndarray-strides": "github:stdlib-js/ndarray-strides#main", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.1.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "@stdlib/bench": "^0.1.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -113,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..aa71cb5 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 0b1c557f2dd2f758baa0b8df3cba4c1d39622aa7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 08:44:55 +0000 Subject: [PATCH 54/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2102e81..3dbf7f0 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.1.0", "@stdlib/ndarray-shape": "^0.1.0", "@stdlib/ndarray-strides": "^0.1.0", - "@stdlib/string-format": "^0.1.1", + "@stdlib/error-tools-fmtprodmsg": "^0.1.1", "@stdlib/types": "^0.2.0" }, "devDependencies": { From c8d9a9d3aa1ec9fe88256731313e7692519efa86 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:18:31 +0000 Subject: [PATCH 55/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index 4244f2d..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; // tslint:disable-line:no-unnecessary-generics - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; // tslint:disable-line:no-unnecessary-generics - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index a6094f6..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2023 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":";;k3GA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,CCXA,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,CACR,CCoFA,SAASK,EAAUC,EAAKR,GACvB,IAAIS,EAKJ,OAFAA,EAAI,IAAIC,EAASC,EAAUH,GAAOI,EAASJ,GAAOK,EAAUL,GAAOM,EAAYN,GAAOO,EAAWP,GAAOQ,EAAUR,IAEnG,YAAVR,EA7GN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIS,KAAMd,IAErB,OAAOD,CACR,CAmGSgB,CAAST,GAEF,WAAVT,EA5FN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIS,KAAMd,GAEtB,OAAOD,CACR,CAkFSiB,CAAQV,GAxEjB,SAAgBD,EAAKR,GACpB,IACID,EACAG,EACAkB,EACAC,EACAC,EACAnB,EAQJ,GAJAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,SAIV4B,EAAIC,EAAkBrB,IACfsB,iBAGN,IAFAJ,EAAME,EAAEG,UAAW,GACnBJ,EAAMK,GAkBP,SAAkBvB,GACjB,OAAOK,EAAIS,KAAMd,EACjB,GApB2B,EAAGwB,EAAc3B,IACtCG,EAAI,EAAGA,EAAIJ,EAAKI,IACrBiB,EAAKlB,EAAKC,EAAGkB,EAAKlB,SAGnB,IAAMA,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIS,KAAMd,GAGvB,OAAOD,CAYR,CAoCQ0B,CAAOnB,EAAGT,EAClB,CClIA,SAAS6B,EAAaC,EAAOC,EAAOC,GACnC,IAAI9B,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAI6B,EAAMF,EAAO3B,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAI2B,EAAO3B,IACvBD,EAAIG,KAAM0B,EAAO5B,IAElB,OAAOD,CACR,CCEA,SAAS+B,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjC,EACAkC,EACAC,EACAlC,EACAmC,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxC,QAEZQ,EAAM,GACS,cAAViC,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnC,EAAI,EAAGA,EAAImC,EAAGnC,IACnBD,EAAIG,KAAMgC,GAEX,IAAMlC,EAAI,EAAGA,EAAIiC,EAAGjC,IACnBD,EAAIG,KAAM6B,EAAS/B,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAImC,EAAGnC,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiC,EAAGjC,IACnBD,EAAIG,KAAM6B,EAAS/B,GAEpB,CACD,OAAOD,CACR,CCdA,IAAIsC,ECpBI,CACNC,QAAWC,EAASC,IAAK,WACzBC,MAAQ,EACR5C,MAAS0C,EAASC,IAAK,kBACvBE,SAAW,EACXC,KAAQJ,EAASC,IAAK,cACtBX,MAAS,EACTG,MAASO,EAASC,IAAK,SACvBI,UAAY,GDwEd,SAASC,IACR,IAAIC,EACAf,EACApC,EACAoD,EACAf,EACAnC,EACAmD,EACApB,EACAD,EACAsB,EACAC,EACAC,EACAvD,EAEAwD,EAEJ,GAA0B,IAArBC,UAAU9D,OACd,GAAKF,EAAmBgE,UAAW,IAClC1D,EAAS0D,UAAW,GACpBP,EAAU,CAAA,MACJ,CAEN,IAAMQ,EADNR,EAAUO,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,qGAAsGV,IAEpI,GAAKW,EAAYX,EAAS,YAEnBzD,EADNM,EAASmD,EAAQnD,QAEhB,MAAM,IAAI4D,UAAWC,EAAQ,qHAAsH,SAAU7D,GAG/J,KACK,CAEN,IAAMN,EADNM,EAAS0D,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,oHAAqH7D,IAGnJ,IAAM2D,EADNR,EAAUO,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,qEAAsEV,GAGpG,CAcD,GAbKnD,IACC+D,EAAe/D,IACnBqD,EAAQxC,EAAUb,GAClByD,GAAM,IAENJ,EAAQW,EAAgBhE,GACxByD,GAAM,IAGRH,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFO,EAAYX,EAAS,YAEzB,GADAI,EAAKZ,QAAUQ,EAAQR,SACjBsB,EAAeV,EAAKZ,SACzB,MAAM,IAAIiB,UAAWC,EAAQ,+EAAgF,UAAWN,EAAKZ,eAG9HY,EAAKZ,QAAUD,EAASC,QAEzB,GAAKmB,EAAYX,EAAS,YAEzB,GADAI,EAAKR,QAAUI,EAAQJ,SACjBmB,EAAWX,EAAKR,SACrB,MAAM,IAAIa,UAAWC,EAAQ,+DAAgE,UAAWN,EAAKR,eAG9GQ,EAAKR,QAAUL,EAASK,QAEzB,GAAKe,EAAYX,EAAS,UAEzB,GADAI,EAAKrB,MAAQiB,EAAQjB,OACfiC,EAAsBZ,EAAKrB,OAChC,MAAM,IAAI0B,UAAWC,EAAQ,2EAA4E,QAASN,EAAKrB,aAIxHqB,EAAKrB,MAAQQ,EAASR,MAIvB,GAAK4B,EAAYX,EAAS,SAAY,CAErC,GADAjD,EAAQiD,EAAQjD,OACVkE,EAAYlE,GACjB,MAAM,IAAI0D,UAAWC,EAAQ,4EAA6E,QAAS3D,IAEpH,GAAKmD,IAAUgB,EAAehB,EAAOnD,EAAOqD,EAAKZ,SAChD,MAAM,IAAI2B,MAAOT,EAAQ,2FAA4FN,EAAKZ,QAASU,EAAOnD,GAE3I,MAOCA,EAPUmD,IAILI,GAAiB,YAAVJ,GAGJA,EAGDX,EAASxC,MAElB,GAAK4D,EAAYX,EAAS,UAEzB,GAAe,SADfd,EAAQc,EAAQd,QACkB,SAAVA,EAClBoB,EAEW,QAAVpB,EAMHA,EADY,IAHPkC,EAAevD,EAAYhB,IAIxB0C,EAASL,MAETnB,EAAUlB,GAIA,SAAVqC,IACTA,EAAQnB,EAAUlB,IAGnBqC,EAAQK,EAASL,WAEZ,IAAMmC,EAASnC,GACrB,MAAM,IAAIuB,UAAWC,EAAQ,wEAAyE,QAASxB,SAGhHA,EAAQK,EAASL,MAiBlB,GAfKyB,EAAYX,EAAS,QACzBG,EAAMN,KAAOG,EAAQH,KAErBM,EAAMN,KAAON,EAASM,KAElBc,EAAYX,EAAS,WACzBG,EAAMmB,QAAUtB,EAAQsB,QAExBnB,EAAMmB,QAAU,CAAEnB,EAAMN,MAEpBc,EAAYX,EAAS,YACzBG,EAAML,SAAWE,EAAQF,SAEzBK,EAAML,SAAWP,EAASO,SAEtBa,EAAYX,EAAS,SAEzB,GADAI,EAAKT,KAAOK,EAAQL,MACdoB,EAAWX,EAAKT,MACrB,MAAM,IAAIc,UAAWC,EAAQ,+DAAgE,OAAQN,EAAKT,YAG3GS,EAAKT,KAAOJ,EAASI,KAGtB,GAAKgB,EAAYX,EAAS,SAAY,CAErC,IAAMzD,EADNuC,EAAQkB,EAAQlB,OAEf,MAAM,IAAI2B,UAAWC,EAAQ,0GAA2G,QAAS5B,IAElJD,EAAQC,EAAMrC,OACdK,EAAMyE,EAAOzC,EACb,KAAM,KAAKjC,EAgBX,MAAM,IAAIsE,MAAO,+EAfZb,GAEJzB,GADAC,EAAQlB,EAAUf,IACJJ,OACdK,EAAMyE,EAAOzC,IACFsB,EAAKR,SAAW4B,EAAS3E,IAEpCwD,EADAvB,EAAQ2C,EAAY5E,GAEpBgC,EAAQC,EAAMrC,OACdK,EAAMyE,EAAOzC,KAEbD,EAAQ,EAERC,EAAQ,CADRhC,EAAMD,EAAOJ,QAKd,CAOD,GALKoC,EAAQuB,EAAKrB,QACjBD,EAAQF,EAAaC,EAAOC,EAAOsB,EAAKrB,OACxCF,EAAQuB,EAAKrB,OAGTuB,EAAM,CACV,GAAKiB,EAAO1E,EAAOiC,SAAYhC,EAC9B,MAAM,IAAI4E,WAAY,wIAElBxB,IAAUnD,GAASqD,EAAKT,KAC5B9C,EAASS,EAAUT,EAAQE,IAE3BkC,EAAUpB,EAAYhB,GACtBoD,EAASnC,EAAWjB,GACpBA,EAASc,EAASd,GACboC,EAAQxC,OAASoC,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,IAGlD,MAAM,GAAKrC,EAAS,CAIpB,GAHe,YAAVqD,GAAuBE,EAAKR,UAChC/C,EAAS+C,EAAS/C,EAAQwD,GAAOoB,EAAY5E,IAAU,IAEnDA,EAAOJ,SAAWK,EACtB,MAAM,IAAI4E,WAAY,yIAElBxB,IAAUnD,GAASqD,EAAKT,QAC5B9C,EAASD,EAAYC,EAAQC,EAAKC,GAErC,MACEF,EAAS8E,EAAc5E,EAAOD,GAO/B,YAJiB,IAAZmC,IACJA,EAAU2C,EAAe9C,EAAOI,GAChCe,EAAS4B,EAAgB/C,EAAOG,IAE1B,IAAIxB,EAASV,EAAOF,EAAQiC,EAAOG,EAASgB,EAAQf,EAAOiB,EACnE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index aa71cb5..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5a40bbf8b988201ad2833bc4924b30f1b50b9313 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Jan 2024 15:19:15 +0000 Subject: [PATCH 56/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 128 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 47 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 53 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 89 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 6205 insertions(+), 6392 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 356a51d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-01-01T05:40:45.034Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index 30656c4..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index 3acd3a9..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA corresponding to v0.11.0 - uses: styfle/cancel-workflow-action@b173b6ec0100793626c2d9e6b90435061f4fc3e5 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index c92f5c4..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 62e7e4b..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index e1e3539..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA corresponding to v3.8.1 - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -301,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -361,17 +354,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 5981254..0000000 --- a/branches.md +++ /dev/null @@ -1,53 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers. -- **deno**: [Deno][deno-url] branch for use in Deno. -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments. - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..604158c --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.1.0-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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 ), order === 'column-major' );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index ae00c4c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 3dbf7f0..bda3e50 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.1.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,67 +13,6 @@ "bugs": { "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", - "@stdlib/assert-is-array": "^0.1.1", - "@stdlib/assert-is-boolean": "^0.1.1", - "@stdlib/assert-is-ndarray-like": "^0.1.0", - "@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", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.1.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.1.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.1.0", - "@stdlib/ndarray-base-assert-is-order": "^0.1.1", - "@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", - "@stdlib/ndarray-base-strides2order": "^0.1.1", - "@stdlib/ndarray-ctor": "^0.1.0", - "@stdlib/ndarray-data-buffer": "^0.1.0", - "@stdlib/ndarray-defaults": "^0.1.1", - "@stdlib/ndarray-dtype": "^0.1.0", - "@stdlib/ndarray-offset": "^0.1.0", - "@stdlib/ndarray-order": "^0.1.0", - "@stdlib/ndarray-shape": "^0.1.0", - "@stdlib/ndarray-strides": "^0.1.0", - "@stdlib/error-tools-fmtprodmsg": "^0.1.1", - "@stdlib/types": "^0.2.0" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.1.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.1.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -113,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..dc40fe8 --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From b92915fd4fb8c7ba9c50c7c028b00bbf3c402f5b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 01:26:53 +0000 Subject: [PATCH 57/96] Transform error messages --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 08b8b2a..a6b335a 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.0", "@stdlib/ndarray-shape": "^0.2.0", "@stdlib/ndarray-strides": "^0.2.0", - "@stdlib/string-format": "^0.2.0", + "@stdlib/error-tools-fmtprodmsg": "^0.2.0", "@stdlib/types": "^0.3.1" }, "devDependencies": { From 63c43633953f1d011f633cff497af4754563a781 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:59:08 +0000 Subject: [PATCH 58/96] Remove files --- index.d.ts | 228 -- index.mjs | 4 - index.mjs.map | 1 - stats.html | 6177 ------------------------------------------------- 4 files changed, 6410 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 604158c..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.1.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.1.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.1.1-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.1.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.1.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.1.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.1.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.1.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.1.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.1.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.1.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.1.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.1.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.1.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.1.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.1.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.1.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.1.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.1.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.1.0-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.1.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.1.1-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.1.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.1.1-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.1.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.1.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.1.0-esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.1.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.1.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.1.0-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.1.1-esm/index.mjs";function C(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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 ), order === 'column-major' );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index dc40fe8..0000000 --- a/stats.html +++ /dev/null @@ -1,6177 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 4dc6ad611f6be934317b822a697a8e4bb2277dab Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 04:59:31 +0000 Subject: [PATCH 59/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 --- .github/workflows/publish.yml | 255 - .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ---- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 89 +- stats.html | 6177 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 49 files changed, 6205 insertions(+), 6400 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index 199d68f..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA corresponding to v3.1.3 - uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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,EAAS,IAAK,gBAAiB,EACxC,QAAW,GACX,KAAQA,EAAS,IAAK,YAAa,EACnC,MAAS,EACT,MAASA,EAAS,IAAK,OAAQ,EAC/B,SAAY,EACb,CACD,CAKAD,EAAO,QAAUE,ICrDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EAkBzD,SAASC,EAAYC,EAAQC,EAAKC,EAAQ,CACzC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAON,EAAaK,CAAM,EACrBA,IAAU,UAEd,IADAE,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAI,KAAMJ,EAAQK,CAAE,CAAE,UAEZH,IAAU,SAErB,IADAE,EAAMN,EAAaG,CAAI,EACjBI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,CAAE,EAAIL,EAAQK,CAAE,MAItB,KADAD,EAAM,IAAID,EAAMF,CAAI,EACdI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,CAAE,EAAIL,EAAQK,CAAE,EAGvB,OAAOD,CACR,CAKAR,EAAO,QAAUG,ICrEjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EACrDC,EAAU,QAAS,2BAA4B,EAC/CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAa,QAAS,yBAA0B,EAChDC,GAAY,QAAS,wBAAyB,EAC9CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAU,QAAS,6BAA8B,EAYrD,SAASC,GAASC,EAAM,CACvB,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAMD,EAAI,OACVE,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAI,KAAMF,EAAI,KAAMG,CAAE,CAAE,EAEzB,OAAOD,CACR,CASA,SAASE,GAAQJ,EAAM,CACtB,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAMD,EAAI,OACVE,EAAMX,EAAaU,CAAI,EACjBE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,CAAE,EAAIH,EAAI,KAAMG,CAAE,EAExB,OAAOD,CACR,CAUA,SAASG,GAAOL,EAAKM,EAAQ,CAC5B,IAAIC,EACAN,EACAC,EACAM,EACAC,EACAC,EACAP,EAQJ,GANAI,EAAOjB,EAAagB,CAAM,EAC1BL,EAAMD,EAAI,OACVE,EAAM,IAAIK,EAAMN,CAAI,EAGpBS,EAAIvB,EAAkBe,CAAI,EACrBQ,EAAE,iBAGN,IAFAF,EAAME,EAAE,UAAW,CAAE,EACrBD,EAAMrB,EAAYuB,EAAS,EAAGtB,EAAciB,CAAM,CAAE,EAC9CH,EAAI,EAAGA,EAAIF,EAAKE,IACrBK,EAAKN,EAAKC,EAAGM,EAAKN,CAAE,CAAE,MAGvB,KAAMA,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,CAAE,EAAIH,EAAI,KAAMG,CAAE,EAGzB,OAAOD,EASP,SAASS,EAASR,EAAI,CACrB,OAAOH,EAAI,KAAMG,CAAE,CACpB,CACD,CAwBA,SAASS,GAAUZ,EAAKM,EAAQ,CAC/B,IAAIO,EAKJ,OAFAA,EAAI,IAAIrB,EAASC,GAAUO,CAAI,EAAGF,GAASE,CAAI,EAAGN,GAAUM,CAAI,EAAGL,GAAYK,CAAI,EAAGJ,GAAWI,CAAI,EAAGH,GAAUG,CAAI,CAAE,EAEnHM,IAAU,UACPP,GAASc,CAAE,EAEdP,IAAU,SACPF,GAAQS,CAAE,EAEXR,GAAOQ,EAAGP,CAAM,CACxB,CAKApB,EAAO,QAAU0B,KCtKjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA+BA,SAASC,GAAaC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACA,EAGJ,IADAA,EAAM,CAAC,EACD,EAAI,EAAG,EAAID,EAAMF,EAAO,IAC7BG,EAAI,KAAM,CAAE,EAEb,IAAM,EAAI,EAAG,EAAIH,EAAO,IACvBG,EAAI,KAAMF,EAAO,CAAE,CAAE,EAEtB,OAAOE,CACR,CAKAL,EAAO,QAAUC,KChDjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAM,QAAS,+BAAgC,EAuBnD,SAASC,GAAeC,EAAOC,EAAOC,EAASC,EAAQ,CACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAH,EAAIH,EAAQ,OACZM,EAAIR,EAAQK,EACZD,EAAM,CAAC,EACFD,IAAU,YAAc,CAE5B,IADAG,EAAIR,GAAKI,EAAS,CAAE,CAAE,EAAID,EAAOO,CAAE,EAC7BD,EAAI,EAAGA,EAAIC,EAAGD,IACnBH,EAAI,KAAME,CAAE,EAEb,IAAMC,EAAI,EAAGA,EAAIF,EAAGE,IACnBH,EAAI,KAAMF,EAASK,CAAE,CAAE,CAEzB,KAAO,CACN,IAAMA,EAAI,EAAGA,EAAIC,EAAGD,IACnBH,EAAI,KAAM,CAAE,EAEb,IAAMG,EAAI,EAAGA,EAAIF,EAAGE,IACnBH,EAAI,KAAMF,EAASK,CAAE,CAAE,CAEzB,CACA,OAAOH,CACR,CAKAP,EAAO,QAAUE,KC7EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,gCAAiC,EACrDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,GAAU,QAAS,yBAA0B,EAC7CC,GAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAgB,QAAS,oCAAqC,EAC9DC,GAAiB,QAAS,qCAAsC,EAChEC,GAAgB,QAAS,oCAAqC,EAC9DC,EAAQ,QAAS,4BAA6B,EAC9CC,GAAU,QAAS,sBAAuB,EAC1CC,GAAa,QAAS,0CAA2C,EACjEC,GAAU,QAAS,sCAAuC,EAC1DC,GAAgB,QAAS,6CAA8C,EACvEC,GAAgB,QAAS,uDAAwD,EACjFC,GAAe,QAAS,6BAA8B,EACtDC,GAAiB,QAAS,mCAAoC,EAC9DC,GAAW,QAAS,uBAAwB,EAC5CC,GAAW,QAAS,uBAAwB,EAC5CC,EAAa,QAAS,yBAA0B,EAChDC,GAAY,QAAS,wBAAyB,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,GAAU,QAAS,6BAA8B,EACjDC,EAAa,QAAS,qBAAsB,EAC5CC,GAAU,QAAS,4BAA6B,EAChDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAoB,IACpBC,GAAc,IACdC,GAAa,IACbC,GAAW,IACXC,GAAc,IACdC,GAAgB,IAKhBC,EAAWL,GAAY,EA4D3B,SAASM,IAAQ,CAChB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzB,GAAKtB,EAAmB,UAAW,CAAE,CAAE,EACtCU,EAAS,UAAW,CAAE,EACtBF,EAAU,CAAC,MACL,CAEN,GADAA,EAAU,UAAW,CAAE,EAClB,CAACjC,EAAUiC,CAAQ,EACvB,MAAM,IAAI,UAAWT,EAAQ,qGAAsGS,CAAQ,CAAE,EAE9I,GAAKlC,EAAYkC,EAAS,QAAS,IAClCE,EAASF,EAAQ,OACZ,CAACR,EAAmBU,CAAO,GAC/B,MAAM,IAAI,UAAWX,EAAQ,qHAAsH,SAAUW,CAAO,CAAE,CAGzK,KACM,CAEN,GADAA,EAAS,UAAW,CAAE,EACjB,CAACV,EAAmBU,CAAO,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oHAAqHW,CAAO,CAAE,EAG5J,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjC,EAAUiC,CAAQ,EACvB,MAAM,IAAI,UAAWT,EAAQ,qEAAsES,CAAQ,CAAE,CAG/G,CAcA,GAbKE,IACC/B,GAAe+B,CAAO,GAC1BI,EAAQvB,GAAUmB,CAAO,EACzBY,EAAM,KAENR,EAAQxB,GAAgBoB,CAAO,EAC/BY,EAAM,KAGRL,EAAQ,CAAC,EACTC,EAAO,CAAC,EAGH5C,EAAYkC,EAAS,SAAU,GAEnC,GADAU,EAAK,QAAUV,EAAQ,QAClB,CAACrB,GAAe+B,EAAK,OAAQ,EACjC,MAAM,IAAI,UAAWnB,EAAQ,+EAAgF,UAAWmB,EAAK,OAAQ,CAAE,OAGxIA,EAAK,QAAUZ,EAAS,QAEzB,GAAKhC,EAAYkC,EAAS,SAAU,GAEnC,GADAU,EAAK,QAAUV,EAAQ,QAClB,CAAChC,EAAW0C,EAAK,OAAQ,EAC7B,MAAM,IAAI,UAAWnB,EAAQ,+DAAgE,UAAWmB,EAAK,OAAQ,CAAE,OAGxHA,EAAK,QAAUZ,EAAS,QAEzB,GAAKhC,EAAYkC,EAAS,OAAQ,GAEjC,GADAU,EAAK,MAAQV,EAAQ,MAChB,CAAC9B,GAAsBwC,EAAK,KAAM,EACtC,MAAM,IAAI,UAAWnB,EAAQ,2EAA4E,QAASmB,EAAK,KAAM,CAAE,OAIhIA,EAAK,MAAQZ,EAAS,MAIvB,GAAKhC,EAAYkC,EAAS,OAAQ,EAAI,CAErC,GADAK,EAAQL,EAAQ,MACX,CAACvB,GAAY4B,CAAM,EACvB,MAAM,IAAI,UAAWd,EAAQ,4EAA6E,QAASc,CAAM,CAAE,EAE5H,GAAKC,GAAS,CAAC1B,GAAe0B,EAAOD,EAAOK,EAAK,OAAQ,EACxD,MAAM,IAAI,MAAOnB,EAAQ,2FAA4FmB,EAAK,QAASJ,EAAOD,CAAM,CAAE,CAEpJ,MAAYC,EAIN,CAACQ,GAAOR,IAAU,UACtBD,EAAQP,EAAS,MAEjBO,EAAQC,EAGTD,EAAQP,EAAS,MAElB,GAAKhC,EAAYkC,EAAS,OAAQ,GAEjC,GADAI,EAAQJ,EAAQ,MACXI,IAAU,OAASA,IAAU,OAC5BU,EAECV,IAAU,OAEdS,EAAMvC,GAAeW,EAAYiB,CAAO,CAAE,EAGrCW,IAAQ,EACZT,EAAQN,EAAS,MAEjBM,EAAQjB,EAAUe,CAAO,GAIjBE,IAAU,SACnBA,EAAQjB,EAAUe,CAAO,GAG1BE,EAAQN,EAAS,cAEP,CAACpB,GAAS0B,CAAM,EAC3B,MAAM,IAAI,UAAWb,EAAQ,wEAAyE,QAASa,CAAM,CAAE,OAGxHA,EAAQN,EAAS,MAiBlB,GAfKhC,EAAYkC,EAAS,MAAO,EAChCS,EAAM,KAAOT,EAAQ,KAErBS,EAAM,KAAOX,EAAS,KAElBhC,EAAYkC,EAAS,SAAU,EACnCS,EAAM,QAAUT,EAAQ,QAExBS,EAAM,QAAU,CAAEA,EAAM,IAAK,EAEzB3C,EAAYkC,EAAS,UAAW,EACpCS,EAAM,SAAWT,EAAQ,SAEzBS,EAAM,SAAWX,EAAS,SAEtBhC,EAAYkC,EAAS,MAAO,GAEhC,GADAU,EAAK,KAAOV,EAAQ,KACf,CAAChC,EAAW0C,EAAK,IAAK,EAC1B,MAAM,IAAI,UAAWnB,EAAQ,+DAAgE,OAAQmB,EAAK,IAAK,CAAE,OAGlHA,EAAK,KAAOZ,EAAS,KAGtB,GAAKhC,EAAYkC,EAAS,OAAQ,EAAI,CAErC,GADAO,EAAQP,EAAQ,MACX,CAACR,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWhB,EAAQ,0GAA2G,QAASgB,CAAM,CAAE,EAE1JC,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,CACpB,SAAYL,EACNY,GACJP,EAAQvB,GAAUkB,CAAO,EACzBM,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,GACRG,EAAK,SAAWzC,GAASiC,CAAO,GAC3CK,EAAQlB,EAAYa,CAAO,EAC3BS,EAAMJ,EACNC,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,IAEnBC,EAAQ,EACRI,EAAMV,EAAO,OACbK,EAAQ,CAAEK,CAAI,OAGf,OAAM,IAAI,MAAO,6EAA8E,EAQhG,GALKJ,EAAQE,EAAK,QACjBH,EAAQX,GAAaY,EAAOD,EAAOG,EAAK,KAAM,EAC9CF,EAAQE,EAAK,OAGTI,EAAM,CACV,GAAKvC,EAAO2B,EAAO,KAAM,IAAMU,EAC9B,MAAM,IAAI,WAAY,sIAAuI,EAEzJN,IAAUD,GAASK,EAAK,KAC5BR,EAASP,GAAUO,EAAQG,CAAM,GAEjCJ,EAAUhB,EAAYiB,CAAO,EAC7BC,EAASjB,GAAWgB,CAAO,EAC3BA,EAASd,GAASc,CAAO,EACpBD,EAAQ,OAASO,IAErBP,EAAUJ,GAAeW,EAAOD,EAAON,EAASG,CAAM,GAGzD,SAAYF,EAAS,CAIpB,GAHKI,IAAU,WAAaI,EAAK,UAChCR,EAASZ,GAASY,EAAQS,GAAOtB,EAAYa,CAAO,EAAGE,IAAU,cAAe,GAE5EF,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", "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d81b7f7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.0-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.0-esm/index.mjs";import{isPrimitive as s}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.0-esm/index.mjs";import r from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.0-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.0-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.0-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.0-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.0-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.0-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.0-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.1.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.0-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.0-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.1.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.0-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.0-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.0-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.0-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.0-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.0-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.1.0-esm/index.mjs";import O from"https://cdn.jsdelivr.net/gh/stdlib-js/string-format@v0.1.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.0-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.0-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.0-esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.0-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import M from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.0-esm/index.mjs";import N from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.0-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import G from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import H from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function I(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&z(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default 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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/string-format';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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 ), order === 'column-major' );\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\nexport default array;\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\nimport settings from '@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\nexport default defaults;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","castBuffer","buffer","len","dtype","ctor","out","i","bufferCtors","push","allocUnsafe","copyView","arr","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","iget","generic","binary","set","fcn","o","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","expandShape","ndims","shape","ndmin","expandStrides","strides","order","N","s","j","abs","defaults","casting","settings","get","copy","flatten","mode","readonly","array","options","offset","btype","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","RangeError","createBuffer","shape2strides","strides2offset"],"mappings":";;k4HA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,CCXA,SAASC,EAAYC,EAAQC,EAAKC,GACjC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAOG,EAAaJ,GACL,YAAVA,EAEJ,IADAE,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMP,EAAQK,SAEb,GAAe,WAAVH,EAEX,IADAE,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,QAIpB,IADAD,EAAM,IAAID,EAAMF,GACVI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAML,EAAQK,GAGrB,OAAOD,CACR,CCoFA,SAASK,EAAUC,EAAKR,GACvB,IAAIS,EAKJ,OAFAA,EAAI,IAAIC,EAASC,EAAUH,GAAOI,EAASJ,GAAOK,EAAUL,GAAOM,EAAYN,GAAOO,EAAWP,GAAOQ,EAAUR,IAEnG,YAAVR,EA7GN,SAAkBQ,GACjB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAM,GACAC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAIG,KAAMG,EAAIS,KAAMd,IAErB,OAAOD,CACR,CAmGSgB,CAAST,GAEF,WAAVT,EA5FN,SAAiBQ,GAChB,IAAIT,EACAG,EACAC,EAIJ,IAFAJ,EAAMS,EAAId,OACVQ,EAAMI,EAAaP,GACbI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIS,KAAMd,GAEtB,OAAOD,CACR,CAkFSiB,CAAQV,GAxEjB,SAAgBD,EAAKR,GACpB,IACID,EACAG,EACAkB,EACAC,EACAC,EACAnB,EAQJ,GAJAD,EAAM,IAFCE,EAAaJ,GAEd,CADND,EAAMS,EAAId,SAIV4B,EAAIC,EAAkBrB,IACfsB,iBAGN,IAFAJ,EAAME,EAAEG,UAAW,GACnBJ,EAAMK,GAkBP,SAAkBvB,GACjB,OAAOK,EAAIS,KAAMd,EACjB,GApB2B,EAAGwB,EAAc3B,IACtCG,EAAI,EAAGA,EAAIJ,EAAKI,IACrBiB,EAAKlB,EAAKC,EAAGkB,EAAKlB,SAGnB,IAAMA,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,GAAMK,EAAIS,KAAMd,GAGvB,OAAOD,CAYR,CAoCQ0B,CAAOnB,EAAGT,EAClB,CClIA,SAAS6B,EAAaC,EAAOC,EAAOC,GACnC,IAAI9B,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAI6B,EAAMF,EAAO3B,IAC7BD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAI2B,EAAO3B,IACvBD,EAAIG,KAAM0B,EAAO5B,IAElB,OAAOD,CACR,CCEA,SAAS+B,EAAeH,EAAOC,EAAOG,EAASC,GAC9C,IAAIjC,EACAkC,EACAC,EACAlC,EACAmC,EAKJ,GAFAA,EAAIR,GADJM,EAAIF,EAAQxC,QAEZQ,EAAM,GACS,cAAViC,EAAwB,CAE5B,IADAE,EAAIE,EAAKL,EAAS,IAAQH,EAAOO,GAC3BnC,EAAI,EAAGA,EAAImC,EAAGnC,IACnBD,EAAIG,KAAMgC,GAEX,IAAMlC,EAAI,EAAGA,EAAIiC,EAAGjC,IACnBD,EAAIG,KAAM6B,EAAS/B,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAImC,EAAGnC,IACnBD,EAAIG,KAAM,GAEX,IAAMF,EAAI,EAAGA,EAAIiC,EAAGjC,IACnBD,EAAIG,KAAM6B,EAAS/B,GAEpB,CACD,OAAOD,CACR,CCdA,IAAIsC,ECpBI,CACNC,QAAWC,EAASC,IAAK,WACzBC,MAAQ,EACR5C,MAAS0C,EAASC,IAAK,kBACvBE,SAAW,EACXC,KAAQJ,EAASC,IAAK,cACtBX,MAAS,EACTG,MAASO,EAASC,IAAK,SACvBI,UAAY,GDwEd,SAASC,IACR,IAAIC,EACAf,EACApC,EACAoD,EACAf,EACAnC,EACAmD,EACApB,EACAD,EACAsB,EACAC,EACAC,EACAvD,EAEAwD,EAEJ,GAA0B,IAArBC,UAAU9D,OACd,GAAKF,EAAmBgE,UAAW,IAClC1D,EAAS0D,UAAW,GACpBP,EAAU,CAAA,MACJ,CAEN,IAAMQ,EADNR,EAAUO,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,qGAAsGV,IAEpI,GAAKW,EAAYX,EAAS,YAEnBzD,EADNM,EAASmD,EAAQnD,QAEhB,MAAM,IAAI4D,UAAWC,EAAQ,qHAAsH,SAAU7D,GAG/J,KACK,CAEN,IAAMN,EADNM,EAAS0D,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,oHAAqH7D,IAGnJ,IAAM2D,EADNR,EAAUO,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,qEAAsEV,GAGpG,CAcD,GAbKnD,IACC+D,EAAe/D,IACnBqD,EAAQxC,EAAUb,GAClByD,GAAM,IAENJ,EAAQW,EAAgBhE,GACxByD,GAAM,IAGRH,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFO,EAAYX,EAAS,YAEzB,GADAI,EAAKZ,QAAUQ,EAAQR,SACjBsB,EAAeV,EAAKZ,SACzB,MAAM,IAAIiB,UAAWC,EAAQ,+EAAgF,UAAWN,EAAKZ,eAG9HY,EAAKZ,QAAUD,EAASC,QAEzB,GAAKmB,EAAYX,EAAS,YAEzB,GADAI,EAAKR,QAAUI,EAAQJ,SACjBmB,EAAWX,EAAKR,SACrB,MAAM,IAAIa,UAAWC,EAAQ,+DAAgE,UAAWN,EAAKR,eAG9GQ,EAAKR,QAAUL,EAASK,QAEzB,GAAKe,EAAYX,EAAS,UAEzB,GADAI,EAAKrB,MAAQiB,EAAQjB,OACfiC,EAAsBZ,EAAKrB,OAChC,MAAM,IAAI0B,UAAWC,EAAQ,2EAA4E,QAASN,EAAKrB,aAIxHqB,EAAKrB,MAAQQ,EAASR,MAIvB,GAAK4B,EAAYX,EAAS,SAAY,CAErC,GADAjD,EAAQiD,EAAQjD,OACVkE,EAAYlE,GACjB,MAAM,IAAI0D,UAAWC,EAAQ,4EAA6E,QAAS3D,IAEpH,GAAKmD,IAAUgB,EAAehB,EAAOnD,EAAOqD,EAAKZ,SAChD,MAAM,IAAI2B,MAAOT,EAAQ,2FAA4FN,EAAKZ,QAASU,EAAOnD,GAE3I,MAOCA,EAPUmD,IAILI,GAAiB,YAAVJ,GAGJA,EAGDX,EAASxC,MAElB,GAAK4D,EAAYX,EAAS,UAEzB,GAAe,SADfd,EAAQc,EAAQd,QACkB,SAAVA,EAClBoB,EAEW,QAAVpB,EAMHA,EADY,IAHPkC,EAAevD,EAAYhB,IAIxB0C,EAASL,MAETnB,EAAUlB,GAIA,SAAVqC,IACTA,EAAQnB,EAAUlB,IAGnBqC,EAAQK,EAASL,WAEZ,IAAMmC,EAASnC,GACrB,MAAM,IAAIuB,UAAWC,EAAQ,wEAAyE,QAASxB,SAGhHA,EAAQK,EAASL,MAiBlB,GAfKyB,EAAYX,EAAS,QACzBG,EAAMN,KAAOG,EAAQH,KAErBM,EAAMN,KAAON,EAASM,KAElBc,EAAYX,EAAS,WACzBG,EAAMmB,QAAUtB,EAAQsB,QAExBnB,EAAMmB,QAAU,CAAEnB,EAAMN,MAEpBc,EAAYX,EAAS,YACzBG,EAAML,SAAWE,EAAQF,SAEzBK,EAAML,SAAWP,EAASO,SAEtBa,EAAYX,EAAS,SAEzB,GADAI,EAAKT,KAAOK,EAAQL,MACdoB,EAAWX,EAAKT,MACrB,MAAM,IAAIc,UAAWC,EAAQ,+DAAgE,OAAQN,EAAKT,YAG3GS,EAAKT,KAAOJ,EAASI,KAGtB,GAAKgB,EAAYX,EAAS,SAAY,CAErC,IAAMzD,EADNuC,EAAQkB,EAAQlB,OAEf,MAAM,IAAI2B,UAAWC,EAAQ,0GAA2G,QAAS5B,IAElJD,EAAQC,EAAMrC,OACdK,EAAMyE,EAAOzC,EACb,KAAM,KAAKjC,EAgBX,MAAM,IAAIsE,MAAO,+EAfZb,GAEJzB,GADAC,EAAQlB,EAAUf,IACJJ,OACdK,EAAMyE,EAAOzC,IACFsB,EAAKR,SAAW4B,EAAS3E,IAEpCwD,EADAvB,EAAQ2C,EAAY5E,GAEpBgC,EAAQC,EAAMrC,OACdK,EAAMyE,EAAOzC,KAEbD,EAAQ,EAERC,EAAQ,CADRhC,EAAMD,EAAOJ,QAKd,CAOD,GALKoC,EAAQuB,EAAKrB,QACjBD,EAAQF,EAAaC,EAAOC,EAAOsB,EAAKrB,OACxCF,EAAQuB,EAAKrB,OAGTuB,EAAM,CACV,GAAKiB,EAAO1E,EAAOiC,SAAYhC,EAC9B,MAAM,IAAI4E,WAAY,wIAElBxB,IAAUnD,GAASqD,EAAKT,KAC5B9C,EAASS,EAAUT,EAAQE,IAE3BkC,EAAUpB,EAAYhB,GACtBoD,EAASnC,EAAWjB,GACpBA,EAASc,EAASd,GACboC,EAAQxC,OAASoC,IAErBI,EAAUD,EAAeH,EAAOC,EAAOG,EAASC,IAGlD,MAAM,GAAKrC,EAAS,CAIpB,GAHe,YAAVqD,GAAuBE,EAAKR,UAChC/C,EAAS+C,EAAS/C,EAAQwD,GAAOoB,EAAY5E,GAAoB,iBAAVqC,IAEnDrC,EAAOJ,SAAWK,EACtB,MAAM,IAAI4E,WAAY,yIAElBxB,IAAUnD,GAASqD,EAAKT,QAC5B9C,EAASD,EAAYC,EAAQC,EAAKC,GAErC,MACEF,EAAS8E,EAAc5E,EAAOD,GAO/B,YAJiB,IAAZmC,IACJA,EAAU2C,EAAe9C,EAAOI,GAChCe,EAAS4B,EAAgB/C,EAAOG,IAE1B,IAAIxB,EAASV,EAAOF,EAAQiC,EAAOG,EAASgB,EAAQf,EAAOiB,EACnE"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index ae00c4c..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index a6b335a..3a003f2 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.0", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,67 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.0", - "@stdlib/array-base-flatten": "^0.2.0", - "@stdlib/array-shape": "^0.2.0", - "@stdlib/assert-has-own-property": "^0.2.0", - "@stdlib/assert-is-array": "^0.2.0", - "@stdlib/assert-is-boolean": "^0.2.0", - "@stdlib/assert-is-ndarray-like": "^0.2.0", - "@stdlib/assert-is-nonnegative-integer": "^0.2.0", - "@stdlib/assert-is-plain-object": "^0.2.0", - "@stdlib/buffer-alloc-unsafe": "^0.2.0", - "@stdlib/complex-base-cast-return": "^0.2.0", - "@stdlib/complex-ctors": "^0.2.0", - "@stdlib/constants-float64-pinf": "^0.2.0", - "@stdlib/math-base-assert-is-integer": "^0.2.0", - "@stdlib/math-base-special-abs": "^0.2.0", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.0", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.0", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.0", - "@stdlib/ndarray-base-assert-is-order": "^0.2.0", - "@stdlib/ndarray-base-buffer": "^0.2.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.2.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.0", - "@stdlib/ndarray-base-ctor": "^0.2.0", - "@stdlib/ndarray-base-numel": "^0.2.0", - "@stdlib/ndarray-base-shape2strides": "^0.2.0", - "@stdlib/ndarray-base-strides2offset": "^0.2.0", - "@stdlib/ndarray-base-strides2order": "^0.2.0", - "@stdlib/ndarray-ctor": "^0.2.0", - "@stdlib/ndarray-data-buffer": "^0.2.0", - "@stdlib/ndarray-defaults": "^0.2.0", - "@stdlib/ndarray-dtype": "^0.2.0", - "@stdlib/ndarray-offset": "^0.2.0", - "@stdlib/ndarray-order": "^0.2.0", - "@stdlib/ndarray-shape": "^0.2.0", - "@stdlib/ndarray-strides": "^0.2.0", - "@stdlib/error-tools-fmtprodmsg": "^0.2.0", - "@stdlib/types": "^0.3.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.0", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.0" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -113,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e8ef87f --- /dev/null +++ b/stats.html @@ -0,0 +1,6177 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From fda488c1fc9167f455262436047852387732221c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 15 Feb 2024 06:39:58 +0000 Subject: [PATCH 60/96] Update README.md for ESM bundle v0.2.0 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ee06995..9d76775 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; +import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@v0.2.0-esm/index.mjs'; ``` @@ -227,7 +227,7 @@ var bool = ( v === buf[ 0 ] ); - - - - From 66ad6d0166b814214a32bc77e2e152e6b7fc3ec0 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 21:31:38 +0000 Subject: [PATCH 64/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 228 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 49 files changed, 4870 insertions(+), 6395 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..16df1c8 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.0-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.0-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.0-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.1-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.0-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7159e52..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 9479779..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/buffer-alloc-unsafe": "^0.2.1", - "@stdlib/complex-base-cast-return": "^0.2.1", - "@stdlib/complex-ctors": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/math-base-assert-is-integer": "^0.2.1", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-buffer-ctors": "^0.2.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^0.2.1", - "@stdlib/ndarray-base-strides2order": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-data-buffer": "^0.2.1", - "@stdlib/ndarray-defaults": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/ndarray-offset": "^0.2.1", - "@stdlib/ndarray-order": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..37f81ad --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 29d3f7db478b3ea67ad33fe0b3731d8555af347c Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 25 Feb 2024 22:11:00 +0000 Subject: [PATCH 65/96] Update README.md for ESM bundle v0.2.1 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f0dd281..3fa3a09 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ limitations under the License. ## Usage ```javascript -import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@esm/index.mjs'; +import array from 'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@v0.2.1-esm/index.mjs'; ``` @@ -227,7 +227,7 @@ var bool = ( v === buf[ 0 ] ); - - - - From d2f89165d2d59e02baa3993b7343327d1a9086d4 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 1 Mar 2024 14:14:04 +0000 Subject: [PATCH 69/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 28 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6397 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 4eba76d..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-03-01T06:07:58.248Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index 9106b5d..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA corresponding to v2.0.0 - uses: act10ns/slack@ed1309ab9862e57e9e583e51c7889486b9a00b0f - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d04f2d3 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.2-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7159e52..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index d2a63c9..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/buffer-alloc-unsafe": "^0.2.1", - "@stdlib/complex-base-cast-return": "^0.2.1", - "@stdlib/complex-ctors": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/math-base-assert-is-integer": "^0.2.2", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-buffer-ctors": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^0.2.1", - "@stdlib/ndarray-base-strides2order": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-data-buffer": "^0.2.1", - "@stdlib/ndarray-defaults": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/ndarray-offset": "^0.2.1", - "@stdlib/ndarray-order": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..008d4de --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From bd62c83e04694d949f90e23c1fc674e163402b74 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 07:46:14 +0000 Subject: [PATCH 70/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index ae00c4c..7159e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 9b6b11a..88ff5a9 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From cf45b3fad32114648a1316d8216286a125d1810b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:15:54 +0000 Subject: [PATCH 71/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d04f2d3..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.2-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 008d4de..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From cc6076f93a195d2d00c5a3dfccb4eb7e37ca4c09 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 1 Apr 2024 13:16:11 +0000 Subject: [PATCH 72/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 132 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6400 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 069394e..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2024-04-01T05:23:42.938Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..20b89c1 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.3-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7159e52..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 88ff5a9..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/buffer-alloc-unsafe": "^0.2.1", - "@stdlib/complex-base-cast-return": "^0.2.1", - "@stdlib/complex-ctors": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/math-base-assert-is-integer": "^0.2.3", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-buffer-ctors": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^0.2.1", - "@stdlib/ndarray-base-strides2order": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-data-buffer": "^0.2.1", - "@stdlib/ndarray-defaults": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/ndarray-offset": "^0.2.1", - "@stdlib/ndarray-order": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..d221bd4 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 29735aa71a757ab240c12909b8fc2c5b231f19e9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 03:59:38 +0000 Subject: [PATCH 73/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index ae00c4c..7159e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 521bcdf..92cfefe 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.1", "@stdlib/ndarray-shape": "^0.2.1", "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/string-format": "^0.2.1", + "@stdlib/error-tools-fmtprodmsg": "^0.2.1", "@stdlib/types": "^0.3.2", "@stdlib/error-tools-fmtprodmsg": "^0.2.1" }, From 7dd3672bbf592d30bf69878cce545ef17d0190c1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:31:49 +0000 Subject: [PATCH 74/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index 20b89c1..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.3-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index d221bd4..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 9c02979fccd6af394b874470d4ae944b44166eef Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Fri, 12 Apr 2024 09:32:05 +0000 Subject: [PATCH 75/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 49 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 797 ---- .github/workflows/publish.yml | 249 -- .github/workflows/test.yml | 100 - .github/workflows/test_bundles.yml | 189 - .github/workflows/test_coverage.yml | 134 - .github/workflows/test_install.yml | 86 - .gitignore | 188 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 5 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 --- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 -- branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 18 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 -- examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 +++++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 49 files changed, 4870 insertions(+), 6401 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 60d743f..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = false - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 10a16e6..0000000 --- a/.gitattributes +++ /dev/null @@ -1,49 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/deps/** linguist-vendored=false -/lib/node_modules/** linguist-vendored=false linguist-generated=false -test/fixtures/** linguist-vendored=false -tools/** linguist-vendored=false - -# Override what is considered "documentation" by GitHub's linguist: -examples/** linguist-documentation=false diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index ec90164..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,797 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - steps: ${{ toJson(steps) }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure git: - - name: 'Configure git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 2186957..0000000 --- a/dist/index.js +++ /dev/null @@ -1,18 +0,0 @@ -"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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..f3cbac2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.4-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index 644f909..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic') { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 4c40a44..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7159e52..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 92cfefe..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.1", - "@stdlib/assert-has-own-property": "^0.2.1", - "@stdlib/assert-is-array": "^0.2.1", - "@stdlib/assert-is-boolean": "^0.2.1", - "@stdlib/assert-is-ndarray-like": "^0.2.1", - "@stdlib/assert-is-nonnegative-integer": "^0.2.1", - "@stdlib/assert-is-plain-object": "^0.2.1", - "@stdlib/buffer-alloc-unsafe": "^0.2.1", - "@stdlib/complex-base-cast-return": "^0.2.1", - "@stdlib/complex-ctors": "^0.2.1", - "@stdlib/constants-float64-pinf": "^0.2.1", - "@stdlib/math-base-assert-is-integer": "^0.2.4", - "@stdlib/math-base-special-abs": "^0.2.1", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.1", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.1", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.1", - "@stdlib/ndarray-base-assert-is-order": "^0.2.1", - "@stdlib/ndarray-base-buffer": "^0.2.1", - "@stdlib/ndarray-base-buffer-ctors": "^0.2.1", - "@stdlib/ndarray-base-buffer-dtype": "^0.2.1", - "@stdlib/ndarray-base-ctor": "^0.2.1", - "@stdlib/ndarray-base-numel": "^0.2.1", - "@stdlib/ndarray-base-shape2strides": "^0.2.1", - "@stdlib/ndarray-base-strides2offset": "^0.2.1", - "@stdlib/ndarray-base-strides2order": "^0.2.1", - "@stdlib/ndarray-ctor": "^0.2.1", - "@stdlib/ndarray-data-buffer": "^0.2.1", - "@stdlib/ndarray-defaults": "^0.2.1", - "@stdlib/ndarray-dtype": "^0.2.1", - "@stdlib/ndarray-offset": "^0.2.1", - "@stdlib/ndarray-order": "^0.2.1", - "@stdlib/ndarray-shape": "^0.2.1", - "@stdlib/ndarray-strides": "^0.2.1", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1", - "@stdlib/types": "^0.3.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.1" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.1", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.1" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..bca4376 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 5f233f29feafce0f75ff7bd15182e86639174a7d Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Dec 2024 20:19:59 +0000 Subject: [PATCH 76/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index ae00c4c..7159e52 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 911f323..6fb9bcf 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From f4f944e4890fa6566686f2eed656cd11e59d49d1 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Dec 2024 20:36:34 +0000 Subject: [PATCH 77/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index f3cbac2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.1-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.1-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.1-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.1-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.1-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.1-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.1-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.1-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.1-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.1-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.1-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.1-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.1-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.1-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.1-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.2.1-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.2.1-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.1-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.1-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.1-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.1-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.1-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.1-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.1-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.1-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.4-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.2.1-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.2.1-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.1-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.1-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.1-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.1-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index bca4376..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From a25b8fbe81c8aeb7ea70785cf989eccb198705c9 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Tue, 24 Dec 2024 20:37:15 +0000 Subject: [PATCH 78/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 252 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6784 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 9e1884b..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var R=require("@stdlib/constants-float64-pinf"),U=require("@stdlib/math-base-assert-is-integer");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 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 ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..bca53de --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 7159e52..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ); - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 6fb9bcf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..e75ea8a --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 86b3437b1bca33d17e2b1d0be07a09304d1515b2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 03:49:22 +0000 Subject: [PATCH 79/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d2decc..31d8d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 911f323..6fb9bcf 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 6476c2c65b24e2bb31f10e4cc6ff367870cb8678 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 03:50:04 +0000 Subject: [PATCH 80/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index bca53de..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', 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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index e75ea8a..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From fafe7ad674c4ac2698c0b665c7d931d9f2078124 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Sun, 29 Dec 2024 03:50:28 +0000 Subject: [PATCH 81/96] Auto-generated commit --- .editorconfig | 181 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 190 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 264 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6796 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 0779e8a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,181 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 -insert_final_newline = false - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index 26c7956..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 89d007e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..b14d2e2 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function G(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 31d8d2a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 6fb9bcf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..ec29262 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From f3c5487c4d24676764c05e0811b669b4eeb09438 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:22:53 +0000 Subject: [PATCH 82/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d2decc..31d8d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 911f323..6fb9bcf 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From d75bcb98d783f7065ac117e5494f4b79b567b9eb Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:52:55 +0000 Subject: [PATCH 83/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index b14d2e2..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2024 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@esm/index.mjs";import F from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@esm/index.mjs";function G(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index ec29262..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 31a429843e3f8cba350a889c5d4a9bc1f45b9743 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Feb 2025 01:53:16 +0000 Subject: [PATCH 84/96] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 264 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 51 files changed, 4870 insertions(+), 6800 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 772fc3a..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-02-24T01:13:11.527Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 89d007e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e2c3af5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 31d8d2a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 6fb9bcf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1865f64 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 69d8feb6150b587910c2ae3d8f7c11f247547e17 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 01:27:04 +0000 Subject: [PATCH 85/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d2decc..31d8d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 911f323..6fb9bcf 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 65b9bc437883a67d72bb24c1e9337e421a77aed7 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 02:01:07 +0000 Subject: [PATCH 86/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e2c3af5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":";;46GA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,CCgGA,SAASC,EAAUC,EAAKC,GACvB,IAAIC,EAKJ,OAFAA,EAAI,IAAIC,EAASC,EAAUJ,GAAOK,EAASL,GAAOM,EAAUN,GAAOO,EAAYP,GAAOQ,EAAWR,GAAOS,EAAUT,IAEnG,YAAVC,EA7GN,SAAkBD,GACjB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAMb,EAAIc,KAAMF,IAErB,OAAOD,CACR,CAmGSI,CAASb,GAEF,WAAVD,EA5FN,SAAiBD,GAChB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAMK,EAAaN,GACbE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAMZ,EAAIc,KAAMF,GAEtB,OAAOD,CACR,CAkFSM,CAAQf,GAxEjB,SAAgBF,EAAKC,GACpB,IACIS,EACAC,EACAO,EACAC,EACAC,EACAR,EAQJ,GAJAD,EAAM,IAFCU,EAAapB,GAEd,CADNS,EAAMV,EAAIJ,SAIVwB,EAAIE,EAAkBX,IACfY,iBAGN,IAFAL,EAAME,EAAEI,UAAW,GACnBL,EAAMM,GAkBP,SAAkBb,GACjB,OAAOZ,EAAIc,KAAMF,EACjB,GApB2B,EAAGc,EAAczB,IACtCW,EAAI,EAAGA,EAAIF,EAAKE,IACrBM,EAAKP,EAAKC,EAAGO,EAAKP,SAGnB,IAAMA,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAMZ,EAAIc,KAAMF,GAGvB,OAAOD,CAYR,CAoCQgB,CAAOzB,EAAGD,EAClB,CCvGA,IAAI2B,ECpBI,CACNC,QAAWC,EAASC,IAAK,WACzBC,MAAQ,EACR/B,MAAS6B,EAASC,IAAK,kBACvBE,SAAW,EACXC,KAAQJ,EAASC,IAAK,cACtBI,MAAS,EACTC,MAASN,EAASC,IAAK,SACvBM,UAAY,GDwEd,SAASC,IACR,IAAIC,EACAC,EACAC,EACAC,EACAN,EACAnC,EACA0C,EACAC,EACAC,EACAC,EACAC,EACAC,EACAtC,EAEAuC,EAEJ,GAA0B,IAArBC,UAAUtD,OACd,GAAKF,EAAmBwD,UAAW,IAClCT,EAASS,UAAW,GACpBX,EAAU,CAAA,MACJ,CAEN,IAAMY,EADNZ,EAAUW,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAYf,EAAS,YAEnB7C,EADN+C,EAASF,EAAQE,QAEhB,MAAM,IAAIW,UAAWC,EAAQ,QAAS,SAAUZ,GAGlD,KACK,CAEN,IAAM/C,EADN+C,EAASS,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASZ,IAGvC,IAAMU,EADNZ,EAAUW,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAASd,GAGvC,CAcD,GAbKE,IACCc,EAAed,IACnBE,EAAQvC,EAAUqC,GAClBQ,GAAM,IAENN,EAAQa,EAAgBf,IAAY,UACpCQ,GAAM,IAGRH,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFO,EAAYf,EAAS,YAEzB,GADAQ,EAAKlB,QAAUU,EAAQV,SACjB4B,EAAeV,EAAKlB,SACzB,MAAM,IAAIuB,UAAWC,EAAQ,QAAS,UAAWN,EAAKlB,eAGvDkB,EAAKlB,QAAUD,EAASC,QAEzB,GAAKyB,EAAYf,EAAS,YAEzB,GADAQ,EAAKd,QAAUM,EAAQN,SACjByB,EAAWX,EAAKd,SACrB,MAAM,IAAImB,UAAWC,EAAQ,QAAS,UAAWN,EAAKd,eAGvDc,EAAKd,QAAUL,EAASK,QAEzB,GAAKqB,EAAYf,EAAS,UAEzB,GADAQ,EAAKZ,MAAQI,EAAQJ,OACfwB,EAAsBZ,EAAKZ,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASN,EAAKZ,aAIrDY,EAAKZ,MAAQP,EAASO,MAIvB,GAAKmB,EAAYf,EAAS,SAAY,CAErC,GADAtC,EAAQsC,EAAQtC,OACV2D,EAAY3D,GACjB,MAAM,IAAImD,UAAWC,EAAQ,QAAS,QAASpD,IAEhD,GAAK0C,IAAUkB,EAAelB,EAAO1C,EAAO8C,EAAKlB,SAChD,MAAM,IAAIiC,MAAOT,EAAQ,QAASN,EAAKlB,QAASc,EAAO1C,GAExD,MAOCA,EAPU0C,IAILM,GAAiB,YAAVN,GAGJA,EAGDf,EAAS3B,MAElB,GAAKqD,EAAYf,EAAS,UAEzB,GAAe,SADfH,EAAQG,EAAQH,QACkB,SAAVA,EAClBa,EAEW,QAAVb,EAMHA,EADY,IAHP2B,EAAexD,EAAYkC,IAIxBb,EAASQ,MAET3B,EAAUgC,GAIA,SAAVL,IACTA,EAAQ3B,EAAUgC,IAGnBL,EAAQR,EAASQ,WAEZ,IAAM4B,EAAS5B,GACrB,MAAM,IAAIgB,UAAWC,EAAQ,QAAS,QAASjB,SAGhDA,EAAQR,EAASQ,MAiBlB,GAfKkB,EAAYf,EAAS,QACzBO,EAAMZ,KAAOK,EAAQL,KAErBY,EAAMZ,KAAON,EAASM,KAElBoB,EAAYf,EAAS,WACzBO,EAAMmB,QAAU1B,EAAQ0B,QAExBnB,EAAMmB,QAAU,CAAEnB,EAAMZ,MAEpBoB,EAAYf,EAAS,YACzBO,EAAMT,SAAWE,EAAQF,SAEzBS,EAAMT,SAAWT,EAASS,SAEtBiB,EAAYf,EAAS,SAEzB,GADAQ,EAAKf,KAAOO,EAAQP,MACd0B,EAAWX,EAAKf,MACrB,MAAM,IAAIoB,UAAWC,EAAQ,QAAS,OAAQN,EAAKf,YAGpDe,EAAKf,KAAOJ,EAASI,KAGtB,GAAKsB,EAAYf,EAAS,SAAY,CAErC,IAAM7C,EADNkD,EAAQL,EAAQK,OAEf,MAAM,IAAIQ,UAAWC,EAAQ,QAAS,QAAST,IAEhDC,EAAQD,EAAMhD,OACdc,EAAMwD,EAAOtB,EACb,KAAM,KAAKH,EAgBX,MAAM,IAAIqB,MAAOT,EAAO,UAfnBJ,GAEJJ,GADAD,EAAQtC,EAAUmC,IACJ7C,OACdc,EAAMwD,EAAOtB,IACFG,EAAKd,SAAWkC,EAAS1B,IAEpCO,EADAJ,EAAQwB,EAAY3B,GAEpBI,EAAQD,EAAMhD,OACdc,EAAMwD,EAAOtB,KAEbC,EAAQ,EAERD,EAAQ,CADRlC,EAAM+B,EAAO7C,QAKd,CAOD,GALKiD,EAAQE,EAAKZ,QACjBS,EE/QF,SAAsBC,EAAOD,EAAOT,GACnC,IAAIxB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIuB,EAAMU,EAAOjC,IAC7BD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAIiC,EAAOjC,IACvBD,EAAIE,KAAM+B,EAAOhC,IAElB,OAAOD,CACR,CFmQU0D,CAAaxB,EAAOD,EAAOG,EAAKZ,OACxCU,EAAQE,EAAKZ,OAGTc,EAAM,CACV,GAAKiB,EAAOzB,EAAOG,SAAYlC,EAC9B,MAAM,IAAI4D,WAAYjB,EAAO,UAEzBV,IAAU1C,GAAS8C,EAAKf,KAC5BS,EAAS1C,EAAU0C,EAAQxC,IAE3BuC,EAAUjC,EAAYkC,GACtBC,EAASlC,EAAWiC,GACpBA,EAASpC,EAASoC,GACbD,EAAQ5C,OAASiD,IAErBL,EGjRJ,SAAwBK,EAAOD,EAAOJ,EAASJ,GAC9C,IAAIzB,EACA4D,EACAC,EACA5D,EACA6D,EAKJ,GAFAA,EAAI5B,GADJ0B,EAAI/B,EAAQ5C,QAEZe,EAAM,GACS,cAAVyB,EAAwB,CAE5B,IADAoC,EAAIE,EAAKlC,EAAS,IAAQI,EAAO6B,GAC3B7D,EAAI,EAAGA,EAAI6D,EAAG7D,IACnBD,EAAIE,KAAM2D,GAEX,IAAM5D,EAAI,EAAGA,EAAI2D,EAAG3D,IACnBD,EAAIE,KAAM2B,EAAS5B,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAI6D,EAAG7D,IACnBD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAI2D,EAAG3D,IACnBD,EAAIE,KAAM2B,EAAS5B,GAEpB,CACD,OAAOD,CACR,CHsPcgE,CAAe9B,EAAOD,EAAOJ,EAASJ,IAGlD,MAAM,GAAKK,EAAS,CAIpB,GAHe,YAAVE,GAAuBI,EAAKd,SAAWkC,EAAS1B,KACpDA,EAASR,EAASQ,EAAQO,GAAOoB,EAAY3B,GAAoB,iBAAVL,IAEnDK,EAAO7C,SAAWc,EACtB,MAAM,IAAI4D,WAAYjB,EAAO,WAEzBV,IAAU1C,GAAS8C,EAAKf,QAC5BS,EIhSH,SAAqBA,EAAQ/B,EAAKT,GACjC,IAAI2E,EACAjE,EACAC,EAGJ,GADAgE,EAAOvD,EAAapB,GACL,YAAVA,EAEJ,IADAU,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAM4B,EAAQ7B,SAEb,GAAe,WAAVX,EAEX,IADAU,EAAMK,EAAaN,GACbE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAM6B,EAAQ7B,QAIpB,IADAD,EAAM,IAAIiE,EAAMlE,GACVE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAM6B,EAAQ7B,GAGrB,OAAOD,CACR,CJyQYkE,CAAYpC,EAAQ/B,EAAKT,GAErC,MACEwC,EAASqC,EAAc7E,EAAOS,GAO/B,YAJiB,IAAZ8B,IACJA,EAAUuC,EAAenC,EAAOR,GAChCM,EAASsC,EAAgBpC,EAAOJ,IAE1B,IAAIrC,EAASF,EAAOwC,EAAQG,EAAOJ,EAASE,EAAQN,EAAOU,EACnE"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1865f64..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From ba90f662ec65c58458a8cca5be002f480ffb9d3f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 10 Mar 2025 02:01:30 +0000 Subject: [PATCH 87/96] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 264 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 51 files changed, 4870 insertions(+), 6800 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index 2021e95..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-10T01:18:05.380Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 89d007e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\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": "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", - "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e2c3af5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 31d8d2a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 6fb9bcf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1865f64 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From be3514c48f42a09b1c71db4ca181cc62145c472b Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:31:28 +0000 Subject: [PATCH 88/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d2decc..31d8d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 911f323..6fb9bcf 100644 --- a/package.json +++ b/package.json @@ -72,7 +72,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From c0fefb7a9b2eb96b4ce299c90692c44ba9572105 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:32:24 +0000 Subject: [PATCH 89/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e2c3af5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1865f64..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 5732a08dc6dcae63d266454e5a20162f99a82aa2 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Mon, 24 Mar 2025 00:33:22 +0000 Subject: [PATCH 90/96] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/.keepalive | 1 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 264 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 78 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 90 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 51 files changed, 4870 insertions(+), 6800 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/.keepalive delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/.keepalive b/.github/.keepalive deleted file mode 100644 index ed2eae8..0000000 --- a/.github/.keepalive +++ /dev/null @@ -1 +0,0 @@ -2025-03-24T00:30:53.417Z diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 89d007e..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\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,EAAS,IAAK,gBAAiB,EACxC,QAAW,GACX,KAAQA,EAAS,IAAK,YAAa,EACnC,MAAS,EACT,MAASA,EAAS,IAAK,OAAQ,EAC/B,SAAY,EACb,CACD,CAKAD,EAAO,QAAUE,ICrDjB,IAAAC,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EAkBzD,SAASC,EAAYC,EAAQC,EAAKC,EAAQ,CACzC,IAAIC,EACAC,EACAC,EAGJ,GADAF,EAAON,EAAaK,CAAM,EACrBA,IAAU,UAEd,IADAE,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAI,KAAMJ,EAAQK,CAAE,CAAE,UAEZH,IAAU,SAErB,IADAE,EAAMN,EAAaG,CAAI,EACjBI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,CAAE,EAAIL,EAAQK,CAAE,MAItB,KADAD,EAAM,IAAID,EAAMF,CAAI,EACdI,EAAI,EAAGA,EAAIJ,EAAKI,IACrBD,EAAKC,CAAE,EAAIL,EAAQK,CAAE,EAGvB,OAAOD,CACR,CAKAR,EAAO,QAAUG,ICrEjB,IAAAO,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAmB,QAAS,qCAAsC,EAClEC,EAAa,QAAS,kCAAmC,EACzDC,EAAe,QAAS,uBAAwB,EAChDC,EAAc,QAAS,mCAAoC,EAC3DC,EAAc,QAAS,6BAA8B,EACrDC,GAAU,QAAS,2BAA4B,EAC/CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAa,QAAS,yBAA0B,EAChDC,GAAY,QAAS,wBAAyB,EAC9CC,GAAW,QAAS,uBAAwB,EAC5CC,GAAU,QAAS,6BAA8B,EAYrD,SAASC,GAASC,EAAM,CACvB,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAMD,EAAI,OACVE,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAI,KAAMF,EAAI,KAAMG,CAAE,CAAE,EAEzB,OAAOD,CACR,CASA,SAASE,GAAQJ,EAAM,CACtB,IAAIC,EACAC,EACAC,EAIJ,IAFAF,EAAMD,EAAI,OACVE,EAAMX,EAAaU,CAAI,EACjBE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,CAAE,EAAIH,EAAI,KAAMG,CAAE,EAExB,OAAOD,CACR,CAUA,SAASG,GAAOL,EAAKM,EAAQ,CAC5B,IAAIC,EACAN,EACAC,EACAM,EACAC,EACAC,EACAP,EAQJ,GANAI,EAAOjB,EAAagB,CAAM,EAC1BL,EAAMD,EAAI,OACVE,EAAM,IAAIK,EAAMN,CAAI,EAGpBS,EAAIvB,EAAkBe,CAAI,EACrBQ,EAAE,iBAGN,IAFAF,EAAME,EAAE,UAAW,CAAE,EACrBD,EAAMrB,EAAYuB,EAAS,EAAGtB,EAAciB,CAAM,CAAE,EAC9CH,EAAI,EAAGA,EAAIF,EAAKE,IACrBK,EAAKN,EAAKC,EAAGM,EAAKN,CAAE,CAAE,MAGvB,KAAMA,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,CAAE,EAAIH,EAAI,KAAMG,CAAE,EAGzB,OAAOD,EASP,SAASS,EAASR,EAAI,CACrB,OAAOH,EAAI,KAAMG,CAAE,CACpB,CACD,CAwBA,SAASS,GAAUZ,EAAKM,EAAQ,CAC/B,IAAIO,EAKJ,OAFAA,EAAI,IAAIrB,GAASC,GAAUO,CAAI,EAAGF,GAASE,CAAI,EAAGN,GAAUM,CAAI,EAAGL,GAAYK,CAAI,EAAGJ,GAAWI,CAAI,EAAGH,GAAUG,CAAI,CAAE,EAEnHM,IAAU,UACPP,GAASc,CAAE,EAEdP,IAAU,SACPF,GAAQS,CAAE,EAEXR,GAAOQ,EAAGP,CAAM,CACxB,CAKApB,EAAO,QAAU0B,KCtKjB,IAAAE,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cA+BA,SAASC,GAAaC,EAAOC,EAAOC,EAAQ,CAC3C,IAAIC,EACA,EAGJ,IADAA,EAAM,CAAC,EACD,EAAI,EAAG,EAAID,EAAMF,EAAO,IAC7BG,EAAI,KAAM,CAAE,EAEb,IAAM,EAAI,EAAG,EAAIH,EAAO,IACvBG,EAAI,KAAMF,EAAO,CAAE,CAAE,EAEtB,OAAOE,CACR,CAKAL,EAAO,QAAUC,KChDjB,IAAAK,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,GAAM,QAAS,+BAAgC,EAuBnD,SAASC,GAAeC,EAAOC,EAAOC,EAASC,EAAQ,CACtD,IAAIC,EACAC,EACAC,EACAC,EACAC,EAKJ,GAHAH,EAAIH,EAAQ,OACZM,EAAIR,EAAQK,EACZD,EAAM,CAAC,EACFD,IAAU,YAAc,CAE5B,IADAG,EAAIR,GAAKI,EAAS,CAAE,CAAE,EAAID,EAAOO,CAAE,EAC7BD,EAAI,EAAGA,EAAIC,EAAGD,IACnBH,EAAI,KAAME,CAAE,EAEb,IAAMC,EAAI,EAAGA,EAAIF,EAAGE,IACnBH,EAAI,KAAMF,EAASK,CAAE,CAAE,CAEzB,KAAO,CACN,IAAMA,EAAI,EAAGA,EAAIC,EAAGD,IACnBH,EAAI,KAAM,CAAE,EAEb,IAAMG,EAAI,EAAGA,EAAIF,EAAGE,IACnBH,EAAI,KAAMF,EAASK,CAAE,CAAE,CAEzB,CACA,OAAOH,CACR,CAKAP,EAAO,QAAUE,KC7EjB,IAAAU,EAAAC,EAAA,SAAAC,GAAAC,EAAA,cAsBA,IAAIC,EAAa,QAAS,iCAAkC,EACxDC,EAAW,QAAS,gCAAiC,EACrDC,EAAY,QAAS,2BAA4B,EAAE,YACnDC,EAAU,QAAS,yBAA0B,EAC7CC,GAAuB,QAAS,uCAAwC,EAAE,YAC1EC,GAAgB,QAAS,gCAAiC,EAC1DC,GAAgB,QAAS,oCAAqC,EAC9DC,GAAiB,QAAS,qCAAsC,EAChEC,GAAgB,QAAS,oCAAqC,EAC9DC,EAAQ,QAAS,4BAA6B,EAC9CC,GAAU,QAAS,sBAAuB,EAC1CC,GAAa,QAAS,0CAA2C,EACjEC,GAAU,QAAS,sCAAuC,EAC1DC,GAAgB,QAAS,6CAA8C,EACvEC,GAAgB,QAAS,uDAAwD,EACjFC,GAAe,QAAS,6BAA8B,EACtDC,GAAiB,QAAS,mCAAoC,EAC9DC,GAAW,QAAS,uBAAwB,EAC5CC,GAAW,QAAS,uBAAwB,EAC5CC,EAAa,QAAS,yBAA0B,EAChDC,GAAY,QAAS,wBAAyB,EAC9CC,EAAW,QAAS,uBAAwB,EAC5CC,GAAU,QAAS,6BAA8B,EACjDC,EAAa,QAAS,qBAAsB,EAC5CC,GAAU,QAAS,4BAA6B,EAChDC,EAAS,QAAS,uBAAwB,EAC1CC,EAAoB,IACpBC,GAAc,IACdC,GAAa,IACbC,GAAW,IACXC,GAAc,IACdC,GAAgB,IAKhBC,EAAWL,GAAY,EA4D3B,SAASM,IAAQ,CAChB,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EAEJ,GAAK,UAAU,SAAW,EACzB,GAAKtB,EAAmB,UAAW,CAAE,CAAE,EACtCU,EAAS,UAAW,CAAE,EACtBF,EAAU,CAAC,MACL,CAEN,GADAA,EAAU,UAAW,CAAE,EAClB,CAACjC,EAAUiC,CAAQ,EACvB,MAAM,IAAI,UAAWT,EAAQ,qGAAsGS,CAAQ,CAAE,EAE9I,GAAKlC,EAAYkC,EAAS,QAAS,IAClCE,EAASF,EAAQ,OACZ,CAACR,EAAmBU,CAAO,GAC/B,MAAM,IAAI,UAAWX,EAAQ,qHAAsH,SAAUW,CAAO,CAAE,CAGzK,KACM,CAEN,GADAA,EAAS,UAAW,CAAE,EACjB,CAACV,EAAmBU,CAAO,EAC/B,MAAM,IAAI,UAAWX,EAAQ,oHAAqHW,CAAO,CAAE,EAG5J,GADAF,EAAU,UAAW,CAAE,EAClB,CAACjC,EAAUiC,CAAQ,EACvB,MAAM,IAAI,UAAWT,EAAQ,qEAAsES,CAAQ,CAAE,CAG/G,CAcA,GAbKE,IACC/B,GAAe+B,CAAO,GAC1BI,EAAQvB,GAAUmB,CAAO,EACzBY,EAAM,KAENR,EAAQxB,GAAgBoB,CAAO,GAAK,UACpCY,EAAM,KAGRL,EAAQ,CAAC,EACTC,EAAO,CAAC,EAGH5C,EAAYkC,EAAS,SAAU,GAEnC,GADAU,EAAK,QAAUV,EAAQ,QAClB,CAACrB,GAAe+B,EAAK,OAAQ,EACjC,MAAM,IAAI,UAAWnB,EAAQ,+EAAgF,UAAWmB,EAAK,OAAQ,CAAE,OAGxIA,EAAK,QAAUZ,EAAS,QAEzB,GAAKhC,EAAYkC,EAAS,SAAU,GAEnC,GADAU,EAAK,QAAUV,EAAQ,QAClB,CAAChC,EAAW0C,EAAK,OAAQ,EAC7B,MAAM,IAAI,UAAWnB,EAAQ,+DAAgE,UAAWmB,EAAK,OAAQ,CAAE,OAGxHA,EAAK,QAAUZ,EAAS,QAEzB,GAAKhC,EAAYkC,EAAS,OAAQ,GAEjC,GADAU,EAAK,MAAQV,EAAQ,MAChB,CAAC9B,GAAsBwC,EAAK,KAAM,EACtC,MAAM,IAAI,UAAWnB,EAAQ,2EAA4E,QAASmB,EAAK,KAAM,CAAE,OAIhIA,EAAK,MAAQZ,EAAS,MAIvB,GAAKhC,EAAYkC,EAAS,OAAQ,EAAI,CAErC,GADAK,EAAQL,EAAQ,MACX,CAACvB,GAAY4B,CAAM,EACvB,MAAM,IAAI,UAAWd,EAAQ,4EAA6E,QAASc,CAAM,CAAE,EAE5H,GAAKC,GAAS,CAAC1B,GAAe0B,EAAOD,EAAOK,EAAK,OAAQ,EACxD,MAAM,IAAI,MAAOnB,EAAQ,2FAA4FmB,EAAK,QAASJ,EAAOD,CAAM,CAAE,CAEpJ,MAAYC,EAIN,CAACQ,GAAOR,IAAU,UACtBD,EAAQP,EAAS,MAEjBO,EAAQC,EAGTD,EAAQP,EAAS,MAElB,GAAKhC,EAAYkC,EAAS,OAAQ,GAEjC,GADAI,EAAQJ,EAAQ,MACXI,IAAU,OAASA,IAAU,OAC5BU,EAECV,IAAU,OAEdS,EAAMvC,GAAeW,EAAYiB,CAAO,CAAE,EAGrCW,IAAQ,EACZT,EAAQN,EAAS,MAEjBM,EAAQjB,EAAUe,CAAO,GAIjBE,IAAU,SACnBA,EAAQjB,EAAUe,CAAO,GAG1BE,EAAQN,EAAS,cAEP,CAACpB,GAAS0B,CAAM,EAC3B,MAAM,IAAI,UAAWb,EAAQ,wEAAyE,QAASa,CAAM,CAAE,OAGxHA,EAAQN,EAAS,MAiBlB,GAfKhC,EAAYkC,EAAS,MAAO,EAChCS,EAAM,KAAOT,EAAQ,KAErBS,EAAM,KAAOX,EAAS,KAElBhC,EAAYkC,EAAS,SAAU,EACnCS,EAAM,QAAUT,EAAQ,QAExBS,EAAM,QAAU,CAAEA,EAAM,IAAK,EAEzB3C,EAAYkC,EAAS,UAAW,EACpCS,EAAM,SAAWT,EAAQ,SAEzBS,EAAM,SAAWX,EAAS,SAEtBhC,EAAYkC,EAAS,MAAO,GAEhC,GADAU,EAAK,KAAOV,EAAQ,KACf,CAAChC,EAAW0C,EAAK,IAAK,EAC1B,MAAM,IAAI,UAAWnB,EAAQ,+DAAgE,OAAQmB,EAAK,IAAK,CAAE,OAGlHA,EAAK,KAAOZ,EAAS,KAGtB,GAAKhC,EAAYkC,EAAS,OAAQ,EAAI,CAErC,GADAO,EAAQP,EAAQ,MACX,CAACR,EAAmBe,CAAM,EAC9B,MAAM,IAAI,UAAWhB,EAAQ,0GAA2G,QAASgB,CAAM,CAAE,EAE1JC,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,CACpB,SAAYL,EACNY,GACJP,EAAQvB,GAAUkB,CAAO,EACzBM,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,GACRG,EAAK,SAAWzC,EAASiC,CAAO,GAC3CK,EAAQlB,EAAYa,CAAO,EAC3BS,EAAMJ,EACNC,EAAQD,EAAM,OACdK,EAAMrC,EAAOgC,CAAM,IAEnBC,EAAQ,EACRI,EAAMV,EAAO,OACbK,EAAQ,CAAEK,CAAI,OAGf,OAAM,IAAI,MAAO,6EAA8E,EAQhG,GALKJ,EAAQE,EAAK,QACjBH,EAAQX,GAAaY,EAAOD,EAAOG,EAAK,KAAM,EAC9CF,EAAQE,EAAK,OAGTI,EAAM,CACV,GAAKvC,EAAO2B,EAAO,KAAM,IAAMU,EAC9B,MAAM,IAAI,WAAY,sIAAuI,EAEzJN,IAAUD,GAASK,EAAK,KAC5BR,EAASP,GAAUO,EAAQG,CAAM,GAEjCJ,EAAUhB,EAAYiB,CAAO,EAC7BC,EAASjB,GAAWgB,CAAO,EAC3BA,EAASd,GAASc,CAAO,EACpBD,EAAQ,OAASO,IAErBP,EAAUJ,GAAeW,EAAOD,EAAON,EAASG,CAAM,GAGzD,SAAYF,EAAS,CAIpB,GAHKI,IAAU,WAAaI,EAAK,SAAWzC,EAASiC,CAAO,IAC3DA,EAASZ,GAASY,EAAQS,GAAOtB,EAAYa,CAAO,EAAGE,IAAU,cAAe,GAE5EF,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", "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..e2c3af5 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index d910e26..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,78 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( order === 'row-major' ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 31d8d2a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 6fb9bcf..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,68 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -114,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..1865f64 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From 330ae852c024c4be2e4d5983d75b7d156692e3df Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:48:34 +0000 Subject: [PATCH 91/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 3d2decc..31d8d2a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -45,7 +45,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -140,23 +140,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -176,7 +176,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -184,7 +184,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -192,7 +192,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -203,10 +203,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -244,7 +244,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -267,7 +267,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -276,7 +276,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -296,7 +296,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -306,7 +306,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -324,7 +324,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index e10628c..b447d1f 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From c922ae7823a5957d6e6f583ea838b71908ebc022 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:49:03 +0000 Subject: [PATCH 92/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index e2c3af5..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function z(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport abs from '@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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 1865f64..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 30c0ac833f64a827abc612dd90bcd770ac162b77 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 01:49:48 +0000 Subject: [PATCH 93/96] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 265 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 79 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 346 -- package.json | 91 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6802 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index bd7db7d..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Fe,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' );\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 ( isRowMajor( order ) ) {\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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\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": "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", - "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", "isRowMajor", "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..d0708e7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function A(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport abs from '@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 ( isRowMajor( order ) ) {\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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","isRowMajor","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":";;uhHA2CA,SAASA,EAAmBC,GAC3B,MACkB,iBAAVA,GACG,OAAVA,GACwB,iBAAjBA,EAAMC,QACbC,EAAWF,EAAMC,SACjBD,EAAMC,QAAU,GAChBD,EAAMC,OAASE,CAEjB,CCgGA,SAASC,EAAUC,EAAKC,GACvB,IAAIC,EAKJ,OAFAA,EAAI,IAAIC,EAASC,EAAUJ,GAAOK,EAASL,GAAOM,EAAUN,GAAOO,EAAYP,GAAOQ,EAAWR,GAAOS,EAAUT,IAEnG,YAAVC,EA7GN,SAAkBD,GACjB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAMb,EAAIc,KAAMF,IAErB,OAAOD,CACR,CAmGSI,CAASb,GAEF,WAAVD,EA5FN,SAAiBD,GAChB,IAAIU,EACAC,EACAC,EAIJ,IAFAF,EAAMV,EAAIJ,OACVe,EAAMK,EAAaN,GACbE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAMZ,EAAIc,KAAMF,GAEtB,OAAOD,CACR,CAkFSM,CAAQf,GAxEjB,SAAgBF,EAAKC,GACpB,IACIS,EACAC,EACAO,EACAC,EACAC,EACAR,EAQJ,GAJAD,EAAM,IAFCU,EAAapB,GAEd,CADNS,EAAMV,EAAIJ,SAIVwB,EAAIE,EAAkBX,IACfY,iBAGN,IAFAL,EAAME,EAAEI,UAAW,GACnBL,EAAMM,GAkBP,SAAkBb,GACjB,OAAOZ,EAAIc,KAAMF,EACjB,GApB2B,EAAGc,EAAczB,IACtCW,EAAI,EAAGA,EAAIF,EAAKE,IACrBM,EAAKP,EAAKC,EAAGO,EAAKP,SAGnB,IAAMA,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAMZ,EAAIc,KAAMF,GAGvB,OAAOD,CAYR,CAoCQgB,CAAOzB,EAAGD,EAClB,CCvGA,IAAI2B,ECpBI,CACNC,QAAWC,EAASC,IAAK,WACzBC,MAAQ,EACR/B,MAAS6B,EAASC,IAAK,kBACvBE,SAAW,EACXC,KAAQJ,EAASC,IAAK,cACtBI,MAAS,EACTC,MAASN,EAASC,IAAK,SACvBM,UAAY,GDwEd,SAASC,IACR,IAAIC,EACAC,EACAC,EACAC,EACAN,EACAnC,EACA0C,EACAC,EACAC,EACAC,EACAC,EACAC,EACAtC,EAEAuC,EAEJ,GAA0B,IAArBC,UAAUtD,OACd,GAAKF,EAAmBwD,UAAW,IAClCT,EAASS,UAAW,GACpBX,EAAU,CAAA,MACJ,CAEN,IAAMY,EADNZ,EAAUW,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAASd,IAEvC,GAAKe,EAAYf,EAAS,YAEnB7C,EADN+C,EAASF,EAAQE,QAEhB,MAAM,IAAIW,UAAWC,EAAQ,QAAS,SAAUZ,GAGlD,KACK,CAEN,IAAM/C,EADN+C,EAASS,UAAW,IAEnB,MAAM,IAAIE,UAAWC,EAAQ,QAASZ,IAGvC,IAAMU,EADNZ,EAAUW,UAAW,IAEpB,MAAM,IAAIE,UAAWC,EAAQ,QAASd,GAGvC,CAcD,GAbKE,IACCc,EAAed,IACnBE,EAAQvC,EAAUqC,GAClBQ,GAAM,IAENN,EAAQa,EAAgBf,IAAY,UACpCQ,GAAM,IAGRH,EAAQ,CAAA,EACRC,EAAO,CAAA,EAGFO,EAAYf,EAAS,YAEzB,GADAQ,EAAKlB,QAAUU,EAAQV,SACjB4B,EAAeV,EAAKlB,SACzB,MAAM,IAAIuB,UAAWC,EAAQ,QAAS,UAAWN,EAAKlB,eAGvDkB,EAAKlB,QAAUD,EAASC,QAEzB,GAAKyB,EAAYf,EAAS,YAEzB,GADAQ,EAAKd,QAAUM,EAAQN,SACjByB,EAAWX,EAAKd,SACrB,MAAM,IAAImB,UAAWC,EAAQ,QAAS,UAAWN,EAAKd,eAGvDc,EAAKd,QAAUL,EAASK,QAEzB,GAAKqB,EAAYf,EAAS,UAEzB,GADAQ,EAAKZ,MAAQI,EAAQJ,OACfwB,EAAsBZ,EAAKZ,OAChC,MAAM,IAAIiB,UAAWC,EAAQ,QAAS,QAASN,EAAKZ,aAIrDY,EAAKZ,MAAQP,EAASO,MAIvB,GAAKmB,EAAYf,EAAS,SAAY,CAErC,GADAtC,EAAQsC,EAAQtC,OACV2D,EAAY3D,GACjB,MAAM,IAAImD,UAAWC,EAAQ,QAAS,QAASpD,IAEhD,GAAK0C,IAAUkB,EAAelB,EAAO1C,EAAO8C,EAAKlB,SAChD,MAAM,IAAIiC,MAAOT,EAAQ,QAASN,EAAKlB,QAASc,EAAO1C,GAExD,MAOCA,EAPU0C,IAILM,GAAiB,YAAVN,GAGJA,EAGDf,EAAS3B,MAElB,GAAKqD,EAAYf,EAAS,UAEzB,GAAe,SADfH,EAAQG,EAAQH,QACkB,SAAVA,EAClBa,EAEW,QAAVb,EAMHA,EADY,IAHP2B,EAAexD,EAAYkC,IAIxBb,EAASQ,MAET3B,EAAUgC,GAIA,SAAVL,IACTA,EAAQ3B,EAAUgC,IAGnBL,EAAQR,EAASQ,WAEZ,IAAM4B,EAAS5B,GACrB,MAAM,IAAIgB,UAAWC,EAAQ,QAAS,QAASjB,SAGhDA,EAAQR,EAASQ,MAiBlB,GAfKkB,EAAYf,EAAS,QACzBO,EAAMZ,KAAOK,EAAQL,KAErBY,EAAMZ,KAAON,EAASM,KAElBoB,EAAYf,EAAS,WACzBO,EAAMmB,QAAU1B,EAAQ0B,QAExBnB,EAAMmB,QAAU,CAAEnB,EAAMZ,MAEpBoB,EAAYf,EAAS,YACzBO,EAAMT,SAAWE,EAAQF,SAEzBS,EAAMT,SAAWT,EAASS,SAEtBiB,EAAYf,EAAS,SAEzB,GADAQ,EAAKf,KAAOO,EAAQP,MACd0B,EAAWX,EAAKf,MACrB,MAAM,IAAIoB,UAAWC,EAAQ,QAAS,OAAQN,EAAKf,YAGpDe,EAAKf,KAAOJ,EAASI,KAGtB,GAAKsB,EAAYf,EAAS,SAAY,CAErC,IAAM7C,EADNkD,EAAQL,EAAQK,OAEf,MAAM,IAAIQ,UAAWC,EAAQ,QAAS,QAAST,IAEhDC,EAAQD,EAAMhD,OACdc,EAAMwD,EAAOtB,EACb,KAAM,KAAKH,EAgBX,MAAM,IAAIqB,MAAOT,EAAO,UAfnBJ,GAEJJ,GADAD,EAAQtC,EAAUmC,IACJ7C,OACdc,EAAMwD,EAAOtB,IACFG,EAAKd,SAAWkC,EAAS1B,IAEpCO,EADAJ,EAAQwB,EAAY3B,GAEpBI,EAAQD,EAAMhD,OACdc,EAAMwD,EAAOtB,KAEbC,EAAQ,EAERD,EAAQ,CADRlC,EAAM+B,EAAO7C,QAKd,CAOD,GALKiD,EAAQE,EAAKZ,QACjBS,EE/QF,SAAsBC,EAAOD,EAAOT,GACnC,IAAIxB,EACAC,EAGJ,IADAD,EAAM,GACAC,EAAI,EAAGA,EAAIuB,EAAMU,EAAOjC,IAC7BD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAIiC,EAAOjC,IACvBD,EAAIE,KAAM+B,EAAOhC,IAElB,OAAOD,CACR,CFmQU0D,CAAaxB,EAAOD,EAAOG,EAAKZ,OACxCU,EAAQE,EAAKZ,OAGTc,EAAM,CACV,GAAKiB,EAAOzB,EAAOG,SAAYlC,EAC9B,MAAM,IAAI4D,WAAYjB,EAAO,UAEzBV,IAAU1C,GAAS8C,EAAKf,KAC5BS,EAAS1C,EAAU0C,EAAQxC,IAE3BuC,EAAUjC,EAAYkC,GACtBC,EAASlC,EAAWiC,GACpBA,EAASpC,EAASoC,GACbD,EAAQ5C,OAASiD,IAErBL,EGhRJ,SAAwBK,EAAOD,EAAOJ,EAASJ,GAC9C,IAAIzB,EACA4D,EACAC,EACA5D,EACA6D,EAKJ,GAFAA,EAAI5B,GADJ0B,EAAI/B,EAAQ5C,QAEZe,EAAM,GACD+D,EAAYtC,GAAU,CAE1B,IADAoC,EAAIG,EAAKnC,EAAS,IAAQI,EAAO6B,GAC3B7D,EAAI,EAAGA,EAAI6D,EAAG7D,IACnBD,EAAIE,KAAM2D,GAEX,IAAM5D,EAAI,EAAGA,EAAI2D,EAAG3D,IACnBD,EAAIE,KAAM2B,EAAS5B,GAEtB,KAAQ,CACN,IAAMA,EAAI,EAAGA,EAAI6D,EAAG7D,IACnBD,EAAIE,KAAM,GAEX,IAAMD,EAAI,EAAGA,EAAI2D,EAAG3D,IACnBD,EAAIE,KAAM2B,EAAS5B,GAEpB,CACD,OAAOD,CACR,CHqPciE,CAAe/B,EAAOD,EAAOJ,EAASJ,IAGlD,MAAM,GAAKK,EAAS,CAIpB,GAHe,YAAVE,GAAuBI,EAAKd,SAAWkC,EAAS1B,KACpDA,EAASR,EAASQ,EAAQO,GAAOoB,EAAY3B,GAAoB,iBAAVL,IAEnDK,EAAO7C,SAAWc,EACtB,MAAM,IAAI4D,WAAYjB,EAAO,WAEzBV,IAAU1C,GAAS8C,EAAKf,QAC5BS,EIhSH,SAAqBA,EAAQ/B,EAAKT,GACjC,IAAI4E,EACAlE,EACAC,EAGJ,GADAiE,EAAOxD,EAAapB,GACL,YAAVA,EAEJ,IADAU,EAAM,GACAC,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAIE,KAAM4B,EAAQ7B,SAEb,GAAe,WAAVX,EAEX,IADAU,EAAMK,EAAaN,GACbE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAM6B,EAAQ7B,QAIpB,IADAD,EAAM,IAAIkE,EAAMnE,GACVE,EAAI,EAAGA,EAAIF,EAAKE,IACrBD,EAAKC,GAAM6B,EAAQ7B,GAGrB,OAAOD,CACR,CJyQYmE,CAAYrC,EAAQ/B,EAAKT,GAErC,MACEwC,EAASsC,EAAc9E,EAAOS,GAO/B,YAJiB,IAAZ8B,IACJA,EAAUwC,EAAepC,EAAOR,GAChCM,EAASuC,EAAgBrC,EAAOJ,IAE1B,IAAIrC,EAASF,EAAOwC,EAAQG,EAAOJ,EAASE,EAAQN,EAAOU,EACnE"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index 5b7cd5e..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( isRowMajor( order ) ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 31d8d2a..0000000 --- a/lib/main.js +++ /dev/null @@ -1,346 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index b447d1f..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,69 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-row-major-string": "github:stdlib-js/ndarray-base-assert-is-row-major-string#main", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -115,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..15ef5d0 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests From cc153397f50a601b5d597ff13f8f2bcedf27e4ff Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:52:33 +0000 Subject: [PATCH 94/96] Transform error messages --- lib/main.js | 32 ++++++++++++++++---------------- package.json | 2 +- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/main.js b/lib/main.js index 8d596c5..88dcbce 100644 --- a/lib/main.js +++ b/lib/main.js @@ -46,7 +46,7 @@ var getOrder = require( '@stdlib/ndarray-order' ); var getData = require( '@stdlib/ndarray-data-buffer' ); var arrayShape = require( '@stdlib/array-shape' ); var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/string-format' ); +var format = require( '@stdlib/error-tools-fmtprodmsg' ); var isArrayLikeObject = require( './is_array_like_object.js' ); var getDefaults = require( './defaults.js' ); var castBuffer = require( './cast_buffer.js' ); @@ -141,23 +141,23 @@ function array() { } else { options = arguments[ 0 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Must provide either a valid data source, options argument, or both. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT56', options ) ); } if ( hasOwnProp( options, 'buffer' ) ) { buffer = options.buffer; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw 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 ) ); + throw new TypeError( format( '0hT57', 'buffer', buffer ) ); } } } } else { buffer = arguments[ 0 ]; if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( 'invalid option. Data source must be an array-like object, typed-array-like, a Buffer, or an ndarray. Value: `%s`.', buffer ) ); + throw new TypeError( format( '0hT58', buffer ) ); } options = arguments[ 1 ]; if ( !isObject( options ) ) { - throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + throw new TypeError( format( '0hT2V', options ) ); } // Note: we ignore whether `options` has a `buffer` property } @@ -177,7 +177,7 @@ function array() { if ( hasOwnProp( options, 'casting' ) ) { opts.casting = options.casting; if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized casting mode. Option: `%s`.', 'casting', opts.casting ) ); + throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); } } else { opts.casting = defaults.casting; @@ -185,7 +185,7 @@ function array() { if ( hasOwnProp( options, 'flatten' ) ) { opts.flatten = options.flatten; if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'flatten', opts.flatten ) ); + throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); } } else { opts.flatten = defaults.flatten; @@ -193,7 +193,7 @@ function array() { if ( hasOwnProp( options, 'ndmin' ) ) { opts.ndmin = options.ndmin; if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'ndmin', opts.ndmin ) ); + throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); } // 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) } else { @@ -204,10 +204,10 @@ function array() { if ( hasOwnProp( options, 'dtype' ) ) { dtype = options.dtype; if ( !isDataType( dtype ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', dtype ) ); + throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); } if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( 'invalid option. Data type cast is not allowed. Casting mode: `%s`. From: `%s`. To: `%s`.', opts.casting, btype, dtype ) ); + throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); } } else if ( btype ) { // btype !== void 0 // 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. @@ -245,7 +245,7 @@ function array() { order = defaults.order; } } else if ( !isOrder( order ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', order ) ); + throw new TypeError( format( '0hT5C', 'order', order ) ); } } else { order = defaults.order; @@ -268,7 +268,7 @@ function array() { if ( hasOwnProp( options, 'copy' ) ) { opts.copy = options.copy; if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', opts.copy ) ); + throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); } } else { opts.copy = defaults.copy; @@ -277,7 +277,7 @@ function array() { if ( hasOwnProp( options, 'shape' ) ) { shape = options.shape; if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( 'invalid option. `%s` option must be an array-like object containing nonnegative integers. Option: `%s`.', 'shape', shape ) ); + throw new TypeError( format( '0hT5D', 'shape', shape ) ); } ndims = shape.length; len = numel( shape ); @@ -297,7 +297,7 @@ function array() { shape = [ len ]; // assume a 1-dimensional array (vector) } } else { - throw new Error( 'invalid arguments. Must provide either a data source, array shape, or both.' ); + throw new Error( format('0hT0X') ); } // Adjust the array shape to satisfy the minimum number of dimensions... if ( ndims < opts.ndmin ) { @@ -307,7 +307,7 @@ function array() { // 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... if ( FLG ) { if ( numel( buffer.shape ) !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = copyView( buffer, dtype ); @@ -325,7 +325,7 @@ function array() { buffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) ); } if ( buffer.length !== len ) { - throw new RangeError( 'invalid arguments. Array shape is incompatible with provided data source. Number of data source elements does not match array shape.' ); + throw new RangeError( format('0hT0Y') ); } if ( btype !== dtype || opts.copy ) { buffer = castBuffer( buffer, len, dtype ); diff --git a/package.json b/package.json index 44992cf..573f317 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@stdlib/ndarray-order": "^0.2.2", "@stdlib/ndarray-shape": "^0.2.2", "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/string-format": "^0.2.2", + "@stdlib/error-tools-fmtprodmsg": "^0.2.2", "@stdlib/types": "^0.4.3", "@stdlib/error-tools-fmtprodmsg": "^0.2.2" }, From 350ae40f57e28d8336d7019503eec0f16c7e5d9f Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:52:56 +0000 Subject: [PATCH 95/96] Remove files --- index.d.ts | 228 --- index.mjs | 4 - index.mjs.map | 1 - stats.html | 4842 ------------------------------------------------- 4 files changed, 5075 deletions(-) delete mode 100644 index.d.ts delete mode 100644 index.mjs delete mode 100644 index.mjs.map delete mode 100644 stats.html diff --git a/index.d.ts b/index.d.ts deleted file mode 100644 index e0199e1..0000000 --- a/index.d.ts +++ /dev/null @@ -1,228 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -// TypeScript Version: 4.1 - -/// - -import { ArrayLike } from '@stdlib/types/array'; -import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; - -/** -* Interface defining function options. -*/ -interface Options { - /** - * 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) (default: 'float64'). - */ - dtype?: DataType; - - /** - * Specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major'). - */ - order?: Order; - - /** - * Specifies how to handle indices which exceed array dimensions (default: 'throw'). - */ - mode?: Mode; - - /** - * Specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']). - */ - submode?: Array; - - /** - * Boolean indicating whether to copy source data to a new data buffer (default: false). - */ - copy?: boolean; - - /** - * Boolean indicating whether to automatically flatten generic array data sources (default: true). - */ - flatten?: boolean; - - /** - * Minimum number of dimensions (default: 0). - */ - ndmin?: number; - - /** - * Casting rule used to determine what constitutes an acceptable cast (default: 'safe'). - */ - casting?: string; - - /** - * Boolean indicating if an array should be read-only (default: false). - */ - readonly?: boolean; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithShape extends Options { - /** - * Array shape. - */ - shape: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface OptionsWithBuffer extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer: ArrayLike; -} - -/** -* Interface describing function options. -*/ -interface ExtendedOptions extends Options { - /** - * Array shape. - */ - shape?: Shape; - - /** - * Data source. - * - * ## Notes - * - * - If provided along with a `buffer` argument, the argument takes precedence. - */ - buffer?: ArrayLike; -} - -/** -* Returns a multidimensional array. -* -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var opts = { -* 'buffer': [ [ 1, 2 ], [ 3, 4 ] ], -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -*/ -declare function array( options: OptionsWithShape | OptionsWithBuffer ): typedndarray; - -/** -* Returns a multidimensional array. -* -* @param buffer - data source -* @param options - function options -* @param options.buffer - data source -* @param options.dtype - 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) (default: 'float64') -* @param options.order - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) (default: 'row-major') -* @param options.shape - array shape -* @param options.mode - specifies how to handle indices which exceed array dimensions (default: 'throw') -* @param options.submode - specifies how to handle subscripts which exceed array dimensions on a per dimension basis (default: ['throw']) -* @param options.copy - boolean indicating whether to copy source data to a new data buffer (default: false) -* @param options.flatten - boolean indicating whether to automatically flatten generic array data sources (default: true) -* @param options.ndmin - minimum number of dimensions (default: 0) -* @param options.casting - casting rule used to determine what constitutes an acceptable cast (default: 'safe') -* @param options.readonly - boolean indicating whether an array should be read-only -* @throws must provide valid options -* @throws must provide either an array shape, data source, or both -* @throws invalid cast -* @throws data source must be compatible with specified meta data -* @returns ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -declare function array( buffer: ArrayLike, options?: ExtendedOptions ): typedndarray; - - -// EXPORTS // - -export = array; diff --git a/index.mjs b/index.mjs deleted file mode 100644 index d0708e7..0000000 --- a/index.mjs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 -/// -import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function A(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&P(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), order === 'column-major' );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport abs from '@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 ( isRowMajor( order ) ) {\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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","isRowMajor","abs","expandStrides","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/stats.html b/stats.html deleted file mode 100644 index 15ef5d0..0000000 --- a/stats.html +++ /dev/null @@ -1,4842 +0,0 @@ - - - - - - - - Rollup Visualizer - - - -
- - - - - From 12edf68a2993a6f7bd0c347a8fbddb3eccf0e887 Mon Sep 17 00:00:00 2001 From: stdlib-bot Date: Thu, 8 May 2025 08:53:45 +0000 Subject: [PATCH 96/96] Auto-generated commit --- .editorconfig | 180 - .eslintrc.js | 1 - .gitattributes | 66 - .github/PULL_REQUEST_TEMPLATE.md | 7 - .github/workflows/benchmark.yml | 64 - .github/workflows/cancel.yml | 57 - .github/workflows/close_pull_requests.yml | 54 - .github/workflows/examples.yml | 64 - .github/workflows/npm_downloads.yml | 112 - .github/workflows/productionize.yml | 794 --- .github/workflows/publish.yml | 252 - .github/workflows/test.yml | 99 - .github/workflows/test_bundles.yml | 186 - .github/workflows/test_coverage.yml | 133 - .github/workflows/test_install.yml | 85 - .github/workflows/test_published_package.yml | 105 - .gitignore | 194 - .npmignore | 229 - .npmrc | 31 - CHANGELOG.md | 266 - CITATION.cff | 30 - CODE_OF_CONDUCT.md | 3 - CONTRIBUTING.md | 3 - Makefile | 534 -- README.md | 49 +- SECURITY.md | 5 - benchmark/benchmark.js | 1209 ----- benchmark/python/numpy/benchmark.py | 284 - branches.md | 56 - dist/index.d.ts | 3 - dist/index.js | 36 - dist/index.js.map | 7 - docs/repl.txt | 165 - docs/types/test.ts | 269 - examples/index.js | 48 - docs/types/index.d.ts => index.d.ts | 2 +- index.mjs | 4 + index.mjs.map | 1 + lib/cast_buffer.js | 70 - lib/copy_view.js | 167 - lib/defaults.js | 54 - lib/expand_shape.js | 49 - lib/expand_strides.js | 79 - lib/index.js | 71 - lib/is_array_like_object.js | 58 - lib/main.js | 347 -- package.json | 92 +- stats.html | 4842 ++++++++++++++++++ test/dist/test.js | 33 - test/test.js | 126 - 50 files changed, 4870 insertions(+), 6805 deletions(-) delete mode 100644 .editorconfig delete mode 100644 .eslintrc.js delete mode 100644 .gitattributes delete mode 100644 .github/PULL_REQUEST_TEMPLATE.md delete mode 100644 .github/workflows/benchmark.yml delete mode 100644 .github/workflows/cancel.yml delete mode 100644 .github/workflows/close_pull_requests.yml delete mode 100644 .github/workflows/examples.yml delete mode 100644 .github/workflows/npm_downloads.yml delete mode 100644 .github/workflows/productionize.yml delete mode 100644 .github/workflows/publish.yml delete mode 100644 .github/workflows/test.yml delete mode 100644 .github/workflows/test_bundles.yml delete mode 100644 .github/workflows/test_coverage.yml delete mode 100644 .github/workflows/test_install.yml delete mode 100644 .github/workflows/test_published_package.yml delete mode 100644 .gitignore delete mode 100644 .npmignore delete mode 100644 .npmrc delete mode 100644 CHANGELOG.md delete mode 100644 CITATION.cff delete mode 100644 CODE_OF_CONDUCT.md delete mode 100644 CONTRIBUTING.md delete mode 100644 Makefile delete mode 100644 SECURITY.md delete mode 100644 benchmark/benchmark.js delete mode 100644 benchmark/python/numpy/benchmark.py delete mode 100644 branches.md delete mode 100644 dist/index.d.ts delete mode 100644 dist/index.js delete mode 100644 dist/index.js.map delete mode 100644 docs/repl.txt delete mode 100644 docs/types/test.ts delete mode 100644 examples/index.js rename docs/types/index.d.ts => index.d.ts (98%) create mode 100644 index.mjs create mode 100644 index.mjs.map delete mode 100644 lib/cast_buffer.js delete mode 100644 lib/copy_view.js delete mode 100644 lib/defaults.js delete mode 100644 lib/expand_shape.js delete mode 100644 lib/expand_strides.js delete mode 100644 lib/index.js delete mode 100644 lib/is_array_like_object.js delete mode 100644 lib/main.js create mode 100644 stats.html delete mode 100644 test/dist/test.js delete mode 100644 test/test.js diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index dab5d2a..0000000 --- a/.editorconfig +++ /dev/null @@ -1,180 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# EditorConfig configuration file (see ). - -# Indicate that this file is a root-level configuration file: -root = true - -# Set properties for all files: -[*] -end_of_line = lf -charset = utf-8 -trim_trailing_whitespace = true -insert_final_newline = true - -# Set properties for JavaScript files: -[*.{js,js.txt}] -indent_style = tab - -# Set properties for JavaScript ES module files: -[*.{mjs,mjs.txt}] -indent_style = tab - -# Set properties for JavaScript CommonJS files: -[*.{cjs,cjs.txt}] -indent_style = tab - -# Set properties for JSON files: -[*.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `cli_opts.json` files: -[cli_opts.json] -indent_style = tab - -# Set properties for TypeScript files: -[*.ts] -indent_style = tab - -# Set properties for Python files: -[*.{py,py.txt}] -indent_style = space -indent_size = 4 - -# Set properties for Julia files: -[*.{jl,jl.txt}] -indent_style = tab - -# Set properties for R files: -[*.{R,R.txt}] -indent_style = tab - -# Set properties for C files: -[*.{c,c.txt}] -indent_style = tab - -# Set properties for C header files: -[*.{h,h.txt}] -indent_style = tab - -# Set properties for C++ files: -[*.{cpp,cpp.txt}] -indent_style = tab - -# Set properties for C++ header files: -[*.{hpp,hpp.txt}] -indent_style = tab - -# Set properties for Fortran files: -[*.{f,f.txt}] -indent_style = space -indent_size = 2 - -# Set properties for shell files: -[*.{sh,sh.txt}] -indent_style = tab - -# Set properties for AWK files: -[*.{awk,awk.txt}] -indent_style = tab - -# Set properties for HTML files: -[*.{html,html.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for XML files: -[*.{xml,xml.txt}] -indent_style = tab -tab_width = 2 - -# Set properties for CSS files: -[*.{css,css.txt}] -indent_style = tab - -# Set properties for Makefiles: -[Makefile] -indent_style = tab - -[*.{mk,mk.txt}] -indent_style = tab - -# Set properties for Markdown files: -[*.{md,md.txt}] -indent_style = space -indent_size = 4 -trim_trailing_whitespace = true # Note: this disables using two spaces to force a hard line break, which is permitted in Markdown. As we don't typically follow that practice (TMK), we should be safe to automatically trim. - -# Set properties for `usage.txt` files: -[usage.txt] -indent_style = space -indent_size = 2 - -# Set properties for `repl.txt` files: -[repl.txt] -indent_style = space -indent_size = 4 - -# Set properties for `package.json` files: -[package.{json,json.txt}] -indent_style = space -indent_size = 2 - -# Set properties for `datapackage.json` files: -[datapackage.json] -indent_style = space -indent_size = 2 - -# Set properties for `manifest.json` files: -[manifest.json] -indent_style = space -indent_size = 2 - -# Set properties for `tsconfig.json` files: -[tsconfig.json] -indent_style = space -indent_size = 2 - -# Set properties for LaTeX files: -[*.{tex,tex.txt}] -indent_style = tab - -# Set properties for LaTeX Bibliography files: -[*.{bib,bib.txt}] -indent_style = tab - -# Set properties for YAML files: -[*.{yml,yml.txt}] -indent_style = space -indent_size = 2 - -# Set properties for GYP files: -[binding.gyp] -indent_style = space -indent_size = 2 - -[*.gypi] -indent_style = space -indent_size = 2 - -# Set properties for citation files: -[*.{cff,cff.txt}] -indent_style = space -indent_size = 2 diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 5f30286..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1 +0,0 @@ -/* For the `eslint` rules of this project, consult the main repository at https://github.com/stdlib-js/stdlib */ diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 1c88e69..0000000 --- a/.gitattributes +++ /dev/null @@ -1,66 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2017 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Configuration file which assigns attributes to pathnames. -# -# [1]: https://git-scm.com/docs/gitattributes - -# Automatically normalize the line endings of any committed text files: -* text=auto - -# Override line endings for certain files on checkout: -*.crlf.csv text eol=crlf - -# Denote that certain files are binary and should not be modified: -*.png binary -*.jpg binary -*.jpeg binary -*.gif binary -*.ico binary -*.gz binary -*.zip binary -*.7z binary -*.mp3 binary -*.mp4 binary -*.mov binary - -# Override what is considered "vendored" by GitHub's linguist: -/lib/node_modules/** -linguist-vendored -linguist-generated - -# Configure directories which should *not* be included in GitHub language statistics: -/deps/** linguist-vendored -/dist/** linguist-generated -/workshops/** linguist-vendored - -benchmark/** linguist-vendored -docs/* linguist-documentation -etc/** linguist-vendored -examples/** linguist-documentation -scripts/** linguist-vendored -test/** linguist-vendored -tools/** linguist-vendored - -# Configure files which should *not* be included in GitHub language statistics: -Makefile linguist-vendored -*.mk linguist-vendored -*.jl linguist-vendored -*.py linguist-vendored -*.R linguist-vendored - -# Configure files which should be included in GitHub language statistics: -docs/types/*.d.ts -linguist-documentation diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index ddcb33a..0000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,7 +0,0 @@ - - -We are excited about your pull request, but unfortunately we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. - -If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. You may also consult the [development guide](https://github.com/stdlib-js/stdlib/blob/develop/docs/contributing/development.md) for help on developing stdlib. - -We look forward to receiving your contribution! :smiley: \ No newline at end of file diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml deleted file mode 100644 index e4f10fe..0000000 --- a/.github/workflows/benchmark.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: benchmark - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run benchmarks: - benchmark: - - # Define a display name: - name: 'Run benchmarks' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run benchmarks: - - name: 'Run benchmarks' - run: | - npm run benchmark diff --git a/.github/workflows/cancel.yml b/.github/workflows/cancel.yml deleted file mode 100644 index b5291db..0000000 --- a/.github/workflows/cancel.yml +++ /dev/null @@ -1,57 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: cancel - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to cancel existing workflow runs: - cancel: - - # Define a display name: - name: 'Cancel workflow runs' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Time limit: - timeout-minutes: 3 - - # Define the sequence of job steps... - steps: - - # Cancel existing workflow runs: - - name: 'Cancel existing workflow runs' - # Pin action to full length commit SHA - uses: styfle/cancel-workflow-action@85880fa0301c86cca9da44039ee3bb12d3bedbfa # v0.12.1 - with: - workflow_id: >- - benchmark.yml, - examples.yml, - test.yml, - test_coverage.yml, - test_install.yml, - publish.yml - access_token: ${{ github.token }} diff --git a/.github/workflows/close_pull_requests.yml b/.github/workflows/close_pull_requests.yml deleted file mode 100644 index c9faa1b..0000000 --- a/.github/workflows/close_pull_requests.yml +++ /dev/null @@ -1,54 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: close_pull_requests - -# Workflow triggers: -on: - pull_request_target: - types: [opened] - -# Workflow jobs: -jobs: - - # Define job to close all pull requests: - run: - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Close pull request - - name: 'Close pull request' - # Pin action to full length commit SHA corresponding to v3.1.2 - uses: superbrothers/close-pull-request@9c18513d320d7b2c7185fb93396d0c664d5d8448 - with: - comment: | - Thank you for submitting a pull request. :raised_hands: - - We greatly appreciate your willingness to submit a contribution. However, we are not accepting pull requests against this repository, as all development happens on the [main project repository](https://github.com/stdlib-js/stdlib). - - We kindly request that you submit this pull request against the [respective directory](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array) of the main repository where we’ll review and provide feedback. If this is your first stdlib contribution, be sure to read the [contributing guide](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md) which provides guidelines and instructions for submitting contributions. - - Thank you again, and we look forward to receiving your contribution! :smiley: - - Best, - The stdlib team \ No newline at end of file diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 2984901..0000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,64 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2021 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: examples - -# Workflow triggers: -on: - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job to run the package examples... - examples: - - # Define display name: - name: 'Run examples' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - - # Checkout repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Run examples: - - name: 'Run examples' - run: | - npm run examples diff --git a/.github/workflows/npm_downloads.yml b/.github/workflows/npm_downloads.yml deleted file mode 100644 index b7f0018..0000000 --- a/.github/workflows/npm_downloads.yml +++ /dev/null @@ -1,112 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: npm_downloads - -# Workflow triggers: -on: - # Run this workflow weekly: - schedule: - # cron: ' ' - - cron: '35 11 * * 6' - - # Allow the workflow to be manually run: - workflow_dispatch: - -# Workflow jobs: -jobs: - - # Define a job for retrieving npm download counts... - npm_downloads: - - # Define display name: - name: 'Retrieve npm download counts' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - timeout-minutes: 10 - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Resolve package name: - - name: 'Resolve package name' - id: package_name - run: | - name=`node -e 'console.log(require("./package.json").name)' | tr -d '\n'` - echo "package_name=$name" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Fetch download data: - - name: 'Fetch data' - id: download_data - run: | - url="https://api.npmjs.org/downloads/range/$(date --date='1 year ago' '+%Y-%m-%d'):$(date '+%Y-%m-%d')/${{ steps.package_name.outputs.package_name }}" - echo "$url" - data=$(curl "$url") - mkdir ./tmp - echo "$data" > ./tmp/npm_downloads.json - echo "data=$data" >> $GITHUB_OUTPUT - timeout-minutes: 5 - - # Print summary of download data: - - name: 'Print summary' - run: | - echo "| Date | Downloads |" >> $GITHUB_STEP_SUMMARY - echo "|------|------------|" >> $GITHUB_STEP_SUMMARY - cat ./tmp/npm_downloads.json | jq -r ".downloads | .[-14:] | to_entries | map(\"| \(.value.day) | \(.value.downloads) |\") |.[]" >> $GITHUB_STEP_SUMMARY - - # Upload the download data: - - name: 'Upload data' - # Pin action to full length commit SHA - uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 - with: - # Define a name for the uploaded artifact (ensuring a unique name for each job): - name: npm_downloads - - # Specify the path to the file to upload: - path: ./tmp/npm_downloads.json - - # Specify the number of days to retain the artifact (default is 90 days): - retention-days: 90 - timeout-minutes: 10 - if: success() - - # Send data to events server: - - name: 'Post data' - # Pin action to full length commit SHA - uses: distributhor/workflow-webhook@48a40b380ce4593b6a6676528cd005986ae56629 # v3.0.3 - env: - webhook_url: ${{ secrets.STDLIB_NPM_DOWNLOADS_URL }} - webhook_secret: ${{ secrets.STDLIB_WEBHOOK_SECRET }} - data: '{ "downloads": ${{ steps.download_data.outputs.data }} }' - timeout-minutes: 5 - if: success() diff --git a/.github/workflows/productionize.yml b/.github/workflows/productionize.yml deleted file mode 100644 index f4575e9..0000000 --- a/.github/workflows/productionize.yml +++ /dev/null @@ -1,794 +0,0 @@ -#/ -# @license Apache-2.0 -# -# Copyright (c) 2022 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -#/ - -# Workflow name: -name: productionize - -# Workflow triggers: -on: - # Run workflow when a new commit is pushed to the main branch: - push: - branches: - - main - - # Allow the workflow to be manually run: - workflow_dispatch: - inputs: - require-passing-tests: - description: 'Require passing tests for creating bundles' - type: boolean - default: true - - # Run workflow upon completion of `publish` workflow run: - workflow_run: - workflows: ["publish"] - types: [completed] - - -# Concurrency group to prevent multiple concurrent executions: -concurrency: - group: productionize - cancel-in-progress: true - -# Workflow jobs: -jobs: - - # Define a job to create a production build... - productionize: - - # Define display name: - name: 'Productionize' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Define the sequence of job steps... - steps: - # Checkout main branch of repository: - - name: 'Checkout main branch' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - ref: main - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Create production branch: - - name: 'Create production branch' - run: | - git checkout -b production - - # Transform error messages: - - name: 'Transform error messages' - id: transform-error-messages - uses: stdlib-js/transform-errors-action@main - - # Change `@stdlib/string-format` to `@stdlib/error-tools-fmtprodmsg` in package.json if the former is a dependency, otherwise insert it as a dependency: - - name: 'Update dependencies in package.json' - run: | - PKG_VERSION=$(npm view @stdlib/error-tools-fmtprodmsg version) - if grep -q '"@stdlib/string-format"' package.json; then - sed -i "s/\"@stdlib\/string-format\": \"^.*\"/\"@stdlib\/error-tools-fmtprodmsg\": \"^$PKG_VERSION\"/g" package.json - else - node -e "var pkg = require( './package.json' ); pkg.dependencies[ '@stdlib/error-tools-fmtprodmsg' ] = '^$PKG_VERSION'; require( 'fs' ).writeFileSync( 'package.json', JSON.stringify( pkg, null, 2 ) );" - fi - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Transform error messages" - - # Push changes: - - name: 'Push changes' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" production --force - - # Define a job for running tests of the productionized code... - test: - - # Define a display name: - name: 'Run Tests' - - # Define the type of virtual host machine: - runs-on: 'ubuntu-latest' - - # Indicate that this job depends on the prior job finishing: - needs: productionize - - # Run this job regardless of the outcome of the prior job: - if: always() - - # Define the sequence of job steps... - steps: - - # Checkout the repository: - - name: 'Checkout repository' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - with: - # Use the `production` branch: - ref: production - - # Install Node.js: - - name: 'Install Node.js' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Build native add-on if present: - - name: 'Build native add-on (if present)' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - run: | - if [ -f "binding.gyp" ]; then - npm install node-gyp --no-save && ./node_modules/.bin/node-gyp rebuild - fi - - # Run tests: - - name: 'Run tests' - if: ${{ github.event.inputs.require-passing-tests == 'true' }} - id: tests - run: | - npm test || npm test || npm test - - # Define job to create a bundle for use in Deno... - deno: - - # Define display name: - name: 'Create Deno bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `deno` branch exists: - - name: 'Check if remote `deno` branch exists' - id: deno-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin deno - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `deno` exists, delete everything in branch and merge `production` into it - - name: 'If `deno` exists, delete everything in branch and merge `production` into it' - if: steps.deno-branch-exists.outputs.remote-exists - run: | - git checkout -b deno origin/deno - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `deno` does not exist, create `deno` branch: - - name: 'If `deno` does not exist, create `deno` branch' - if: ${{ steps.deno-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b deno - - # Copy files to deno directory: - - name: 'Copy files to deno directory' - run: | - mkdir -p deno - cp README.md LICENSE CONTRIBUTORS NOTICE ./deno - - # Copy TypeScript definitions to deno directory: - if [ -d index.d.ts ]; then - cp index.d.ts ./deno/index.d.ts - fi - if [ -e ./docs/types/index.d.ts ]; then - cp ./docs/types/index.d.ts ./deno/mod.d.ts - fi - - # Install Node.js: - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: Install production and development dependencies - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Bundle package for use in Deno: - - name: 'Bundle package for Deno' - id: deno-bundle - uses: stdlib-js/bundle-action@main - with: - target: 'deno' - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - # Replace links to other packages with links to the deno branch: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/"; - - # Replace reference to `@stdlib/types` with CDN link: - find ./deno -type f -name '*.ts' -print0 | xargs -0 -r sed -Ei "s/\/\/\/ /\/\/\/ /g" - - # Change wording of project description to avoid reference to JavaScript and Node.js: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g" - - # Rewrite all `require()`s to use jsDelivr links: - find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// { - s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i - s/@stdlib/https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js/ - s/';/@deno\/mod.js';/ - }" - - # Rewrite first `import` to show importing of named exports if available: - exports=$(cat lib/index.js | \ - grep -E 'setReadOnly\(.*,.*,.*\)' | \ - sed -E 's/setReadOnly\((.*),(.*),(.*)\);/\2/' | \ - sed -E "s/'//g" | \ - sort) - if [ -n "$exports" ]; then - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\nimport\s+([a-zA-Z0-9_]+)\s+from\s*'([^']+)';\n\`\`\`/\`\`\`javascript\nimport \1 from '\2';\n\`\`\`\n\nYou can also import the following named exports from the package:\n\n\`\`\`javascript\nimport { $(echo $exports | sed -E 's/ /, /g') } from '\2';\n\`\`\`/" - fi - - # Remove `installation`, `cli`, and `c` sections: - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Create package.json file for deno branch: - jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json - - # Delete everything in current directory aside from deno folder: - - name: 'Delete everything in current directory aside from deno folder' - run: | - find . -type 'f' | grep -v -e "deno" -e ".git/" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e "deno" -e ".git" | xargs -r rm -rf - - # Move deno directory to root: - - name: 'Move deno directory to root' - run: | - mv ./deno/* . - rmdir ./deno - - # Commit changes: - - name: 'Commit changes' - run: | - git add -A - git commit -m "Auto-generated commit" - - # Push changes to `deno` branch: - - name: 'Push changes to `deno` branch' - run: | - SLUG=${{ github.repository }} - echo "Pushing changes to $SLUG..." - git push "https://$GITHUB_ACTOR:$GITHUB_TOKEN@github.com/$SLUG.git" deno - - # Send status to Slack channel if job fails: - - name: 'Send status to Slack channel in case of failure' - # Pin action to full length commit SHA - uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2 - with: - status: ${{ job.status }} - channel: '#npm-ci' - if: failure() - - # Define job to create a UMD bundle... - umd: - - # Define display name: - name: 'Create UMD bundle' - - # Define the type of virtual host machine on which to run the job: - runs-on: ubuntu-latest - - # Indicate that this job depends on the test job finishing: - needs: test - - # Define the sequence of job steps... - steps: - # Checkout the repository: - - name: 'Checkout repository' - # Pin action to full length commit SHA - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 - - # Configure Git: - - name: 'Configure Git' - run: | - git config --local user.email "noreply@stdlib.io" - git config --local user.name "stdlib-bot" - - # Check if remote `umd` branch exists: - - name: 'Check if remote `umd` branch exists' - id: umd-branch-exists - continue-on-error: true - run: | - git fetch --all - git ls-remote --exit-code --heads origin umd - if [ $? -eq 0 ]; then - echo "remote-exists=true" >> $GITHUB_OUTPUT - else - echo "remote-exists=false" >> $GITHUB_OUTPUT - fi - - # If `umd` exists, delete everything in branch and merge `production` into it - - name: 'If `umd` exists, delete everything in branch and merge `production` into it' - if: steps.umd-branch-exists.outputs.remote-exists - run: | - git checkout -b umd origin/umd - - find . -type 'f' | grep -v -e ".git/" -e "package.json" -e "README.md" -e "LICENSE" -e "CONTRIBUTORS" -e "NOTICE" | xargs -r rm - find . -mindepth 1 -type 'd' | grep -v -e ".git" | xargs -r rm -rf - - git add -A - git commit -m "Remove files" --allow-empty - - git config merge.theirs.name 'simulate `-s theirs`' - git config merge.theirs.driver 'cat %B > %A' - GIT_CONFIG_PARAMETERS="'merge.default=theirs'" git merge origin/production --allow-unrelated-histories - - # Copy files from `production` branch if necessary: - git checkout origin/production -- . - if [ -n "$(git status --porcelain)" ]; then - git add -A - git commit -m "Auto-generated commit" - fi - - # If `umd` does not exist, create `umd` branch: - - name: 'If `umd` does not exist, create `umd` branch' - if: ${{ steps.umd-branch-exists.outputs.remote-exists == false }} - run: | - git checkout production - git checkout -b umd - - # Copy files to umd directory: - - name: 'Copy files to umd directory' - run: | - mkdir -p umd - cp README.md LICENSE CONTRIBUTORS NOTICE ./umd - - # Install Node.js - - name: 'Install Node.js' - # Pin action to full length commit SHA - uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1 - with: - node-version: 20 - timeout-minutes: 5 - - # Install dependencies: - - name: 'Install production and development dependencies' - id: install - run: | - npm install || npm install || npm install - timeout-minutes: 15 - - # Extract alias: - - name: 'Extract alias' - id: extract-alias - run: | - alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/') - echo "alias=${alias}" >> $GITHUB_OUTPUT - - # Create Universal Module Definition (UMD) Node.js bundle: - - name: 'Create Universal Module Definition (UMD) Node.js bundle' - id: umd-bundle-node - uses: stdlib-js/bundle-action@main - with: - target: 'umd-node' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Create Universal Module Definition (UMD) browser bundle: - - name: 'Create Universal Module Definition (UMD) browser bundle' - id: umd-bundle-browser - uses: stdlib-js/bundle-action@main - with: - target: 'umd-browser' - alias: ${{ steps.extract-alias.outputs.alias }} - - # Rewrite file contents: - - name: 'Rewrite file contents' - run: | - - # Replace links to other packages with links to the umd branch: - find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/fanyv88.com:443\/https\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/"; - - # Remove `installation`, `cli`, and `c` sections: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/
[^<]+<\/section>//g;" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.cli \-\->//g" - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?
[\s\S]+<\!\-\- \/.c \-\->//g" - - # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag: - find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/fanyv88.com:443\/https\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/browser.js' \)\n\`\`\`\n\nTo vendor stdlib functionality and avoid installing dependency trees for Node.js, you can use the UMD server build:\n\n\`\`\`javascript\nvar \2 = require\( 'path\/to\/vendor\/umd\/\3\/index.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n + + ```
@@ -303,7 +294,7 @@ str = JSON.stringify( arr.toJSON() ); ## Notice -This package is part of [stdlib][stdlib], a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. +This package is part of [stdlib][stdlib], a standard library with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more. For more information on the project, filing bug reports and feature requests, and guidance on how to develop [stdlib][stdlib], see the main project [repository][stdlib]. @@ -366,17 +357,17 @@ Copyright © 2016-2025. The Stdlib [Authors][stdlib-authors]. [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-array/main/LICENSE -[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray-dtypes/tree/esm -[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic +[@stdlib/array/generic]: https://github.com/stdlib-js/array-generic/tree/esm -[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed +[@stdlib/array/typed]: https://github.com/stdlib-js/array-typed/tree/esm -[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor +[@stdlib/buffer/ctor]: https://github.com/stdlib-js/buffer-ctor/tree/esm -[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray-ctor/tree/esm diff --git a/SECURITY.md b/SECURITY.md deleted file mode 100644 index 9702d4c..0000000 --- a/SECURITY.md +++ /dev/null @@ -1,5 +0,0 @@ -# Security - -> Policy for reporting security vulnerabilities. - -See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security). diff --git a/benchmark/benchmark.js b/benchmark/benchmark.js deleted file mode 100644 index b26f789..0000000 --- a/benchmark/benchmark.js +++ /dev/null @@ -1,1209 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bench = require( '@stdlib/bench-harness' ); -var Float32Array = require( '@stdlib/array-float32' ); -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var pkg = require( './../package.json' ).name; -var array = require( './../lib' ); - - -// MAIN // - -bench( pkg+'::1d,instantiation,linear_buffer', function benchmark( b ) { - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 6 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,ndarray', function benchmark( b ) { - var out; - var arr; - var i; - - arr = array( new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ) ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,default_cast', function benchmark( b ) { - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic' - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::1d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::2d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::3d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,linear_buffer', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,shape', function benchmark( b ) { - var opts; - var out; - var i; - - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,ndarray', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - arr = array( arr, opts ); - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,no_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float32', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,default_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation,dtype_cast', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'dtype': 'float64', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:copy=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'copy': true, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=true', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 5.0, 6.0 ] ] ] ]; - opts = { - 'dtype': 'generic', - 'flatten': true - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::4d,instantiation:dtype=generic,flatten=false', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ]; - opts = { - 'dtype': 'generic', - 'flatten': false, - 'shape': [ 1, 1, 3, 2 ] - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); - -bench( pkg+'::5d,instantiation:ndmin=5', function benchmark( b ) { - var opts; - var out; - var arr; - var i; - - arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] ); - opts = { - 'ndmin': 5 - }; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = array( arr, opts ); - if ( typeof out !== 'object' ) { - b.fail( 'should return an object' ); - } - } - b.toc(); - if ( !isndarrayLike( out ) ) { - b.fail( 'should return an ndarray' ); - } - b.pass( 'benchmark finished' ); - b.end(); -}); diff --git a/benchmark/python/numpy/benchmark.py b/benchmark/python/numpy/benchmark.py deleted file mode 100644 index 2a561ce..0000000 --- a/benchmark/python/numpy/benchmark.py +++ /dev/null @@ -1,284 +0,0 @@ -#!/usr/bin/env python -# -# @license Apache-2.0 -# -# Copyright (c) 2018 The Stdlib Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Benchmark numpy.array.""" - -from __future__ import print_function -import timeit - -REPEATS = 3 -COUNT = [0] # use a list to allow modification within nested scopes - - -def print_version(): - """Print the TAP version.""" - print("TAP version 13") - - -def print_summary(total, passing): - """Print the benchmark summary. - - # Arguments - - * `total`: total number of tests - * `passing`: number of passing tests - - """ - print("#") - print("1.." + str(total)) # TAP plan - print("# total " + str(total)) - print("# pass " + str(passing)) - print("#") - print("# ok") - - -def print_results(iterations, elapsed): - """Print benchmark results. - - # Arguments - - * `iterations`: number of iterations - * `elapsed`: elapsed time (in seconds) - - # Examples - - ``` python - python> print_results(100000, 0.131009101868) - ``` - """ - rate = iterations / elapsed - - print(" ---") - print(" iterations: " + str(iterations)) - print(" elapsed: " + str(elapsed)) - print(" rate: " + str(rate)) - print(" ...") - - -def benchmark(name, setup, stmt, iterations): - """Run a benchmark and print benchmark results. - - # Arguments - - * `name`: benchmark name (suffix) - * `setup`: benchmark setup - * `stmt`: statement to benchmark - * `iterations`: number of iterations - - # Examples - - ``` python - python> benchmark("::random", "from random import random;", "y = random()", 1000000) - ``` - """ - t = timeit.Timer(stmt, setup=setup) - - i = 0 - while i < REPEATS: - print("# python::numpy" + name) - COUNT[0] += 1 - elapsed = t.timeit(number=iterations) - print_results(iterations, elapsed) - print("ok " + str(COUNT[0]) + " benchmark finished") - i += 1 - - -def main(): - """Run the benchmarks.""" - # pylint: disable=too-many-statements - print_version() - - name = "::1d,instantiation,linear_buffer" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,default_cast" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::1d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,default_cast" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::2d,instantiation:flatten=true" - setup = "import numpy as np; x = [[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,default_cast" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::3d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,ndarray" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,no_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float64');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,default_cast" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation,dtype_cast" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]], dtype='float32');" - stmt = "y = np.array(x, dtype='float64')" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=false" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=False)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:copy=true" - setup = "import numpy as np; x = np.array([[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]]);" - stmt = "y = np.array(x, copy=True)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::4d,instantiation:flatten=true" - setup = "import numpy as np; x = [[[[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]]]];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - name = "::5d,instantiation:ndmin=5" - setup = "import numpy as np; x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0];" - stmt = "y = np.array(x)" - iterations = 100000 - benchmark(name, setup, stmt, iterations) - - print_summary(COUNT[0], COUNT[0]) - - -if __name__ == "__main__": - main() diff --git a/branches.md b/branches.md deleted file mode 100644 index 10cb019..0000000 --- a/branches.md +++ /dev/null @@ -1,56 +0,0 @@ - - -# Branches - -This repository has the following branches: - -- **main**: default branch generated from the [stdlib project][stdlib-url], where all development takes place. -- **production**: [production build][production-url] of the package (e.g., reformatted error messages to reduce bundle sizes and thus the number of bytes transmitted over a network). -- **esm**: [ES Module][esm-url] branch for use via a `script` tag without the need for installation and bundlers (see [README][esm-readme]). -- **deno**: [Deno][deno-url] branch for use in Deno (see [README][deno-readme]). -- **umd**: [UMD][umd-url] branch for use in Observable, or in dual browser/Node.js environments (see [README][umd-readme]). - -The following diagram illustrates the relationships among the above branches: - -```mermaid -graph TD; -A[stdlib]-->|generate standalone package|B; -B[main] -->|productionize| C[production]; -C -->|bundle| D[esm]; -C -->|bundle| E[deno]; -C -->|bundle| F[umd]; - -%% click A href "https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array" -%% click B href "https://github.com/stdlib-js/ndarray-array/tree/main" -%% click C href "https://github.com/stdlib-js/ndarray-array/tree/production" -%% click D href "https://github.com/stdlib-js/ndarray-array/tree/esm" -%% click E href "https://github.com/stdlib-js/ndarray-array/tree/deno" -%% click F href "https://github.com/stdlib-js/ndarray-array/tree/umd" -``` - -[stdlib-url]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/array -[production-url]: https://github.com/stdlib-js/ndarray-array/tree/production -[deno-url]: https://github.com/stdlib-js/ndarray-array/tree/deno -[deno-readme]: https://github.com/stdlib-js/ndarray-array/blob/deno/README.md -[umd-url]: https://github.com/stdlib-js/ndarray-array/tree/umd -[umd-readme]: https://github.com/stdlib-js/ndarray-array/blob/umd/README.md -[esm-url]: https://github.com/stdlib-js/ndarray-array/tree/esm -[esm-readme]: https://github.com/stdlib-js/ndarray-array/blob/esm/README.md \ No newline at end of file diff --git a/dist/index.d.ts b/dist/index.d.ts deleted file mode 100644 index fa81bf8..0000000 --- a/dist/index.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -/// -import array from '../docs/types/index'; -export = array; \ No newline at end of file diff --git a/dist/index.js b/dist/index.js deleted file mode 100644 index 313751c..0000000 --- a/dist/index.js +++ /dev/null @@ -1,36 +0,0 @@ -"use strict";var g=function(e,a){return function(){return a||e((a={exports:{}}).exports,a),a.exports}};var T=g(function(Ie,O){"use strict";var U=require("@stdlib/constants-float64-pinf"),G=require("@stdlib/math-base-assert-is-integer");function _(e){return typeof e=="object"&&e!==null&&typeof e.length=="number"&&G(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 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 isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' );\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 ( isRowMajor( order ) ) {\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 isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' );\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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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 ) { // btype !== void 0\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) );\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": "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", - "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", "isRowMajor", "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", "isColumnMajor", "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/docs/repl.txt b/docs/repl.txt deleted file mode 100644 index c40740b..0000000 --- a/docs/repl.txt +++ /dev/null @@ -1,165 +0,0 @@ - -{{alias}}( [buffer,] [options] ) - Returns a multidimensional array. - - Parameters - ---------- - buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. - - options: Object (optional) - Options. - - options.buffer: Array|TypedArray|Buffer|ndarray (optional) - Data source. If provided along with a `buffer` argument, the argument - takes precedence. - - options.dtype: string (optional) - Underlying storage data type. If not specified and a data source is - provided, the data type is inferred from the provided data source. If an - input data source is not of the same type, this option specifies the - data type to which to cast the input data. For non-ndarray generic array - data sources, the function casts generic array data elements to the - default data type. In order to prevent this cast, the `dtype` option - must be explicitly set to `'generic'`. Any time a cast is required, the - `copy` option is set to `true`, as memory must be copied from the data - source to an output data buffer. Default: 'float64'. - - options.order: string (optional) - Specifies the memory layout of the data source as either row-major (C- - style) or column-major (Fortran-style). The option may be one of the - following values: - - - 'row-major': the order of the returned array is row-major. - - 'column-major': the order of the returned array is column-major. - - 'any': if a data source is column-major and not row-major, the order - of the returned array is column-major; otherwise, the order of the - returned array is row-major. - - 'same': the order of the returned array matches the order of an input - data source. - - Note that specifying an order which differs from the order of a - provided data source does *not* entail a conversion from one memory - layout to another. In short, this option is descriptive, not - prescriptive. Default: 'row-major'. - - options.shape: Array (optional) - Array shape (dimensions). If a shape is not specified, the function - attempts to infer a shape based on a provided data source. For example, - if provided a nested array, the function resolves nested array - dimensions. If provided a multidimensional array data source, the - function uses the array's associated shape. For most use cases, such - inference suffices. For the remaining use cases, specifying a shape is - necessary. For example, provide a shape to create a multidimensional - array view over a linear data buffer, ignoring any existing shape meta - data associated with a provided data source. - - options.flatten: boolean (optional) - Boolean indicating whether to automatically flatten generic array data - sources. If an array shape is not specified, the shape is inferred from - the dimensions of nested arrays prior to flattening. If a use case - requires partial flattening, partially flatten prior to invoking this - function and set the option value to `false` to prevent further - flattening during invocation. Default: true. - - options.copy: boolean (optional) - Boolean indicating whether to (shallow) copy source data to a new data - buffer. The function does *not* perform a deep copy. To prevent - undesired shared changes in state for generic arrays containing objects, - perform a deep copy prior to invoking this function. Default: false. - - options.ndmin: integer (optional) - Specifies the minimum number of dimensions. If an array shape has fewer - dimensions than required by `ndmin`, the function prepends singleton - dimensions to the array shape in order to satisfy the dimensions - requirement. Default: 0. - - options.casting: string (optional) - Specifies the casting rule used to determine acceptable casts. The - option may be one of the following values: - - - 'none': only allow casting between identical types. - - 'equiv': allow casting between identical and byte swapped types. - - 'safe': only allow "safe" casts. - - 'mostly-safe': allow "safe casts" and, for floating-point data types, - downcasts. - - 'same-kind': allow "safe" casts and casts within the same kind (e.g., - between signed integers or between floats). - - 'unsafe': allow casting between all types (including between integers - and floats). - - Default: 'safe'. - - options.codegen: boolean (optional) - Boolean indicating whether to use code generation. Code generation can - boost performance, but may be problematic in browser contexts enforcing - a strict content security policy (CSP). Default: true. - - options.mode: string (optional) - Specifies how to handle indices which exceed array dimensions. The - option may be one of the following values: - - - 'throw': an ndarray instance throws an error when an index exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative indices and - throws an error when an index exceeds array dimensions. - - 'wrap': an ndarray instance wraps around indices exceeding array - dimensions using modulo arithmetic. - - 'clamp', an ndarray instance sets an index exceeding array dimensions - to either `0` (minimum index) or the maximum index. - - Default: 'throw'. - - options.submode: Array (optional) - Specifies how to handle subscripts which exceed array dimensions. If a - mode for a corresponding dimension is equal to - - - 'throw': an ndarray instance throws an error when a subscript exceeds - array dimensions. - - 'normalize': an ndarray instance normalizes negative subscripts and - throws an error when a subscript exceeds array dimensions. - - 'wrap': an ndarray instance wraps around subscripts exceeding array - dimensions using modulo arithmetic. - - 'clamp': an ndarray instance sets a subscript exceeding array - dimensions to either `0` (minimum index) or the maximum index. - - If the number of modes is fewer than the number of dimensions, the - function recycles modes using modulo arithmetic. - - Default: [ options.mode ]. - - options.readonly: boolean (optional) - Boolean indicating whether an array should be read-only. Default: false. - - Returns - ------- - out: ndarray - Multidimensional array. - - Examples - -------- - // Create a 2x2 matrix: - > var arr = {{alias}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ) - - - // Get an element using subscripts: - > var v = arr.get( 1, 1 ) - 4.0 - - // Get an element using a linear index: - > v = arr.iget( 3 ) - 4.0 - - // Set an element using subscripts: - > arr.set( 1, 1, 40.0 ); - > arr.get( 1, 1 ) - 40.0 - - // Set an element using a linear index: - > arr.iset( 3, 99.0 ); - > arr.get( 1, 1 ) - 99.0 - - See Also - -------- - diff --git a/docs/types/test.ts b/docs/types/test.ts deleted file mode 100644 index b58b3d7..0000000 --- a/docs/types/test.ts +++ /dev/null @@ -1,269 +0,0 @@ -/* -* @license Apache-2.0 -* -* Copyright (c) 2021 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -import array = require( './index' ); - - -// TESTS // - -// The function returns an ndarray... -{ - array( [ [ 1, 2 ], [ 3, 4 ] ] ); // $ExpectType typedndarray - array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'shape': [ 2, 2 ] } ); // $ExpectType typedndarray - array( { 'buffer': [ [ 1, 2 ], [ 3, 4 ] ] } ); // $ExpectType typedndarray -} - -// The compiler throws an error if the function is provided a first argument which is not an array, buffer, or options object... -{ - array( true ); // $ExpectError - array( false ); // $ExpectError - array( undefined ); // $ExpectError - array( 5 ); // $ExpectError - array( null ); // $ExpectError -} - -// The compiler throws an error if the function is provided a second argument which is not an options object... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, 'abc' ); // $ExpectError - array( buffer, true ); // $ExpectError - array( buffer, false ); // $ExpectError - array( buffer, null ); // $ExpectError - array( buffer, [] ); // $ExpectError - array( buffer, ( x: number ): number => x ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `dtype` option which is not a recognized data type... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'dtype': 'abc' } ); // $ExpectError - array( buffer, { 'dtype': 123 } ); // $ExpectError - array( buffer, { 'dtype': true } ); // $ExpectError - array( buffer, { 'dtype': false } ); // $ExpectError - array( buffer, { 'dtype': null } ); // $ExpectError - array( buffer, { 'dtype': [] } ); // $ExpectError - array( buffer, { 'dtype': {} } ); // $ExpectError - array( buffer, { 'dtype': ( x: number ): number => x } ); // $ExpectError - - array( { 'dtype': 'abc' } ); // $ExpectError - array( { 'dtype': 123 } ); // $ExpectError - array( { 'dtype': true } ); // $ExpectError - array( { 'dtype': false } ); // $ExpectError - array( { 'dtype': null } ); // $ExpectError - array( { 'dtype': [] } ); // $ExpectError - array( { 'dtype': {} } ); // $ExpectError - array( { 'dtype': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `order` option which is not a recognized order... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'order': 'abc' } ); // $ExpectError - array( buffer, { 'order': 123 } ); // $ExpectError - array( buffer, { 'order': true } ); // $ExpectError - array( buffer, { 'order': false } ); // $ExpectError - array( buffer, { 'order': null } ); // $ExpectError - array( buffer, { 'order': [] } ); // $ExpectError - array( buffer, { 'order': {} } ); // $ExpectError - array( buffer, { 'order': ( x: number ): number => x } ); // $ExpectError - - array( { 'order': 'abc' } ); // $ExpectError - array( { 'order': 123 } ); // $ExpectError - array( { 'order': true } ); // $ExpectError - array( { 'order': false } ); // $ExpectError - array( { 'order': null } ); // $ExpectError - array( { 'order': [] } ); // $ExpectError - array( { 'order': {} } ); // $ExpectError - array( { 'order': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `shape` option which is not an array-like object containing numbers... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'shape': 'abc' } ); // $ExpectError - array( buffer, { 'shape': 123 } ); // $ExpectError - array( buffer, { 'shape': true } ); // $ExpectError - array( buffer, { 'shape': false } ); // $ExpectError - array( buffer, { 'shape': null } ); // $ExpectError - array( buffer, { 'shape': {} } ); // $ExpectError - array( buffer, { 'shape': ( x: number ): number => x } ); // $ExpectError - - array( { 'shape': 'abc' } ); // $ExpectError - array( { 'shape': 123 } ); // $ExpectError - array( { 'shape': true } ); // $ExpectError - array( { 'shape': false } ); // $ExpectError - array( { 'shape': null } ); // $ExpectError - array( { 'shape': {} } ); // $ExpectError - array( { 'shape': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `mode` option which is not a recognized mode... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'mode': 'abc' } ); // $ExpectError - array( buffer, { 'mode': 123 } ); // $ExpectError - array( buffer, { 'mode': true } ); // $ExpectError - array( buffer, { 'mode': false } ); // $ExpectError - array( buffer, { 'mode': null } ); // $ExpectError - array( buffer, { 'mode': [] } ); // $ExpectError - array( buffer, { 'mode': {} } ); // $ExpectError - array( buffer, { 'mode': ( x: number ): number => x } ); // $ExpectError - - array( { 'mode': 'abc' } ); // $ExpectError - array( { 'mode': 123 } ); // $ExpectError - array( { 'mode': true } ); // $ExpectError - array( { 'mode': false } ); // $ExpectError - array( { 'mode': null } ); // $ExpectError - array( { 'mode': [] } ); // $ExpectError - array( { 'mode': {} } ); // $ExpectError - array( { 'mode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an `submode` option which is not an array of strings... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'submode': 'abc' } ); // $ExpectError - array( buffer, { 'submode': 123 } ); // $ExpectError - array( buffer, { 'submode': true } ); // $ExpectError - array( buffer, { 'submode': false } ); // $ExpectError - array( buffer, { 'submode': null } ); // $ExpectError - array( buffer, { 'submode': {} } ); // $ExpectError - array( buffer, { 'submode': ( x: number ): number => x } ); // $ExpectError - - array( { 'submode': 'abc' } ); // $ExpectError - array( { 'submode': 123 } ); // $ExpectError - array( { 'submode': true } ); // $ExpectError - array( { 'submode': false } ); // $ExpectError - array( { 'submode': null } ); // $ExpectError - array( { 'submode': {} } ); // $ExpectError - array( { 'submode': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `copy` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'copy': 'abc' } ); // $ExpectError - array( buffer, { 'copy': 123 } ); // $ExpectError - array( buffer, { 'copy': null } ); // $ExpectError - array( buffer, { 'copy': [] } ); // $ExpectError - array( buffer, { 'copy': {} } ); // $ExpectError - array( buffer, { 'copy': ( x: number ): number => x } ); // $ExpectError - - array( { 'copy': 'abc' } ); // $ExpectError - array( { 'copy': 123 } ); // $ExpectError - array( { 'copy': null } ); // $ExpectError - array( { 'copy': [] } ); // $ExpectError - array( { 'copy': {} } ); // $ExpectError - array( { 'copy': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `flatten` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'flatten': 'abc' } ); // $ExpectError - array( buffer, { 'flatten': 123 } ); // $ExpectError - array( buffer, { 'flatten': null } ); // $ExpectError - array( buffer, { 'flatten': [] } ); // $ExpectError - array( buffer, { 'flatten': {} } ); // $ExpectError - array( buffer, { 'flatten': ( x: number ): number => x } ); // $ExpectError - - array( { 'flatten': 'abc' } ); // $ExpectError - array( { 'flatten': 123 } ); // $ExpectError - array( { 'flatten': null } ); // $ExpectError - array( { 'flatten': [] } ); // $ExpectError - array( { 'flatten': {} } ); // $ExpectError - array( { 'flatten': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `ndmin` option which is not a number... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'ndmin': 'abc' } ); // $ExpectError - array( buffer, { 'ndmin': false } ); // $ExpectError - array( buffer, { 'ndmin': true } ); // $ExpectError - array( buffer, { 'ndmin': null } ); // $ExpectError - array( buffer, { 'ndmin': [] } ); // $ExpectError - array( buffer, { 'ndmin': {} } ); // $ExpectError - array( buffer, { 'ndmin': ( x: number ): number => x } ); // $ExpectError - - array( { 'ndmin': 'abc' } ); // $ExpectError - array( { 'ndmin': false } ); // $ExpectError - array( { 'ndmin': true } ); // $ExpectError - array( { 'ndmin': null } ); // $ExpectError - array( { 'ndmin': [] } ); // $ExpectError - array( { 'ndmin': {} } ); // $ExpectError - array( { 'ndmin': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `casting` option which is not a string... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'casting': 123 } ); // $ExpectError - array( buffer, { 'casting': false } ); // $ExpectError - array( buffer, { 'casting': true } ); // $ExpectError - array( buffer, { 'casting': null } ); // $ExpectError - array( buffer, { 'casting': [] } ); // $ExpectError - array( buffer, { 'casting': {} } ); // $ExpectError - array( buffer, { 'casting': ( x: number ): number => x } ); // $ExpectError - - array( { 'casting': 123 } ); // $ExpectError - array( { 'casting': false } ); // $ExpectError - array( { 'casting': true } ); // $ExpectError - array( { 'casting': null } ); // $ExpectError - array( { 'casting': [] } ); // $ExpectError - array( { 'casting': {} } ); // $ExpectError - array( { 'casting': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided a `readonly` option which is not a boolean... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array( buffer, { 'readonly': 'abc' } ); // $ExpectError - array( buffer, { 'readonly': 123 } ); // $ExpectError - array( buffer, { 'readonly': null } ); // $ExpectError - array( buffer, { 'readonly': [] } ); // $ExpectError - array( buffer, { 'readonly': {} } ); // $ExpectError - array( buffer, { 'readonly': ( x: number ): number => x } ); // $ExpectError - - array( { 'readonly': 'abc' } ); // $ExpectError - array( { 'readonly': 123 } ); // $ExpectError - array( { 'readonly': null } ); // $ExpectError - array( { 'readonly': [] } ); // $ExpectError - array( { 'readonly': {} } ); // $ExpectError - array( { 'readonly': ( x: number ): number => x } ); // $ExpectError -} - -// The compiler throws an error if the function is provided an invalid number of arguments... -{ - const buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); - - array(); // $ExpectError - array( buffer, {}, {} ); // $ExpectError -} diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index 87be905..0000000 --- a/examples/index.js +++ /dev/null @@ -1,48 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -var array = require( './../lib' ); - -// Create a 4-dimensional array containing single-precision floating-point numbers: -var arr = array({ - 'dtype': 'float32', - 'shape': [ 3, 3, 3, 3 ] -}); - -// Retrieve an array value: -var v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 0.0 - -// Set an array value: -arr.set( 1, 2, 1, 2, 10.0 ); - -// Retrieve the array value: -v = arr.get( 1, 2, 1, 2 ); -console.log( v ); -// => 10.0 - -// Serialize the array as a string: -console.log( arr.toString() ); -// => "ndarray( 'float32', new Float32Array( [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ), [ 3, 3, 3, 3 ], [ 27, 9, 3, 1 ], 0, 'row-major' )" - -// Serialize the array as JSON: -console.log( JSON.stringify( arr.toJSON() ) ); -// => '{"type":"ndarray","dtype":"float32","flags":{},"order":"row-major","shape":[3,3,3,3],"strides":[27,9,3,1],"data":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}' diff --git a/docs/types/index.d.ts b/index.d.ts similarity index 98% rename from docs/types/index.d.ts rename to index.d.ts index fd1227a..e0199e1 100644 --- a/docs/types/index.d.ts +++ b/index.d.ts @@ -18,7 +18,7 @@ // TypeScript Version: 4.1 -/// +/// import { ArrayLike } from '@stdlib/types/array'; import { DataType, typedndarray, Mode, Order, Shape } from '@stdlib/types/ndarray'; diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..50585b7 --- /dev/null +++ b/index.mjs @@ -0,0 +1,4 @@ +// Copyright (c) 2025 The Stdlib Authors. License is Apache-2.0: http://www.apache.org/licenses/LICENSE-2.0 +/// +import e from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-has-own-property@v0.2.2-esm/index.mjs";import s from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-plain-object@v0.2.2-esm/index.mjs";import{isPrimitive as r}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-boolean@v0.2.2-esm/index.mjs";import t from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-array@v0.2.2-esm/index.mjs";import{isPrimitive as n}from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-nonnegative-integer@v0.2.2-esm/index.mjs";import i from"https://cdn.jsdelivr.net/gh/stdlib-js/assert-is-ndarray-like@v0.2.2-esm/index.mjs";import d from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-shape2strides@v0.2.2-esm/index.mjs";import o from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2offset@v0.2.2-esm/index.mjs";import m from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-strides2order@v0.2.2-esm/index.mjs";import a from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-numel@v0.2.2-esm/index.mjs";import l from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-ctor@v0.2.2-esm/index.mjs";import h from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-column-major-string@esm/index.mjs";import f from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-data-type@v0.2.2-esm/index.mjs";import p from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-order@v0.2.2-esm/index.mjs";import j from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-casting-mode@v0.2.2-esm/index.mjs";import c from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-allowed-data-type-cast@v0.2.2-esm/index.mjs";import g from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer@v0.3.0-esm/index.mjs";import v from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-dtype@v0.3.0-esm/index.mjs";import b from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-dtype@v0.2.2-esm/index.mjs";import y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-shape@v0.2.2-esm/index.mjs";import u from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-strides@v0.2.2-esm/index.mjs";import x from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-offset@v0.2.2-esm/index.mjs";import w from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-order@v0.2.2-esm/index.mjs";import T from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-data-buffer@v0.2.2-esm/index.mjs";import E from"https://cdn.jsdelivr.net/gh/stdlib-js/array-shape@v0.2.2-esm/index.mjs";import k from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-flatten@v0.2.1-esm/index.mjs";import B from"https://cdn.jsdelivr.net/gh/stdlib-js/error-tools-fmtprodmsg@v0.2.2-esm/index.mjs";import P from"https://cdn.jsdelivr.net/gh/stdlib-js/constants-float64-pinf@v0.2.2-esm/index.mjs";import R from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-assert-is-integer@v0.2.5-esm/index.mjs";import Y from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-defaults@v0.3.0-esm/index.mjs";import C from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-buffer-ctors@v0.3.0-esm/index.mjs";import D from"https://cdn.jsdelivr.net/gh/stdlib-js/buffer-alloc-unsafe@v0.2.2-esm/index.mjs";import V from"https://cdn.jsdelivr.net/gh/stdlib-js/array-base-arraylike2object@v0.2.1-esm/index.mjs";import X from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-base-cast-return@v0.2.2-esm/index.mjs";import _ from"https://cdn.jsdelivr.net/gh/stdlib-js/complex-ctors@v0.2.2-esm/index.mjs";import q from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-ctor@v0.2.2-esm/index.mjs";import z from"https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-base-assert-is-row-major-string@esm/index.mjs";import A from"https://cdn.jsdelivr.net/gh/stdlib-js/math-base-special-abs@v0.2.2-esm/index.mjs";function F(e){return"object"==typeof e&&null!==e&&"number"==typeof e.length&&R(e.length)&&e.length>=0&&e.length= 0 &&\n\t\tvalue.length < PINF\n\t);\n}\n\n\n// EXPORTS //\n\nexport default isArrayLikeObject;\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\nimport arraylike2object from '@stdlib/array-base-arraylike2object';\nimport castReturn from '@stdlib/complex-base-cast-return';\nimport complexCtors from '@stdlib/complex-ctors';\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@stdlib/buffer-alloc-unsafe';\nimport ndarray from '@stdlib/ndarray-base-ctor';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@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* import ndarray from '@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\nexport default 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// MODULES //\n\nimport hasOwnProp from '@stdlib/assert-has-own-property';\nimport isObject from '@stdlib/assert-is-plain-object';\nimport { isPrimitive as isBoolean } from '@stdlib/assert-is-boolean';\nimport isArray from '@stdlib/assert-is-array';\nimport { isPrimitive as isNonNegativeInteger } from '@stdlib/assert-is-nonnegative-integer';\nimport isndarrayLike from '@stdlib/assert-is-ndarray-like';\nimport shape2strides from '@stdlib/ndarray-base-shape2strides';\nimport strides2offset from '@stdlib/ndarray-base-strides2offset';\nimport strides2order from '@stdlib/ndarray-base-strides2order';\nimport numel from '@stdlib/ndarray-base-numel';\nimport ndarray from '@stdlib/ndarray-ctor';\nimport isColumnMajor from '@stdlib/ndarray-base-assert-is-column-major-string';\nimport isDataType from '@stdlib/ndarray-base-assert-is-data-type';\nimport isOrder from '@stdlib/ndarray-base-assert-is-order';\nimport isCastingMode from '@stdlib/ndarray-base-assert-is-casting-mode';\nimport isAllowedCast from '@stdlib/ndarray-base-assert-is-allowed-data-type-cast';\nimport createBuffer from '@stdlib/ndarray-base-buffer';\nimport getBufferDType from '@stdlib/ndarray-base-buffer-dtype';\nimport getDType from '@stdlib/ndarray-dtype';\nimport getShape from '@stdlib/ndarray-shape';\nimport getStrides from '@stdlib/ndarray-strides';\nimport getOffset from '@stdlib/ndarray-offset';\nimport getOrder from '@stdlib/ndarray-order';\nimport getData from '@stdlib/ndarray-data-buffer';\nimport arrayShape from '@stdlib/array-shape';\nimport flatten from '@stdlib/array-base-flatten';\nimport format from '@stdlib/error-tools-fmtprodmsg';\nimport isArrayLikeObject from './is_array_like_object.js';\nimport getDefaults from './defaults.js';\nimport castBuffer from './cast_buffer.js';\nimport copyView from './copy_view.js';\nimport expandShape from './expand_shape.js';\nimport expandStrides from './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* import Float64Array from '@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( '0hT56', 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( '0hT57', '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( '0hT58', buffer ) );\n\t\t}\n\t\toptions = arguments[ 1 ];\n\t\tif ( !isObject( options ) ) {\n\t\t\tthrow new TypeError( format( '0hT2V', 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 ) || 'generic'; // fallback to a \"generic\" dtype when provided, e.g., a generic accessor array as a data source\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( '0hT59', '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( '0hT2o', '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( '0hT2t', '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( '0hTBf', 'dtype', dtype ) );\n\t\t}\n\t\tif ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) {\n\t\t\tthrow new Error( format( '0hT5B', opts.casting, btype, dtype ) );\n\t\t}\n\t} else if ( btype ) { // btype !== void 0\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( '0hT5C', '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( '0hT2o', '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( '0hT5D', '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( format('0hT0X') );\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( format('0hT0Y') );\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 && isArray( buffer ) ) {\n\t\t\tbuffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) );\n\t\t}\n\t\tif ( buffer.length !== len ) {\n\t\t\tthrow new RangeError( format('0hT0Y') );\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\nexport default array;\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\nimport settings from '@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\nexport default 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// 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\nexport default 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\nimport isRowMajor from '@stdlib/ndarray-base-assert-is-row-major-string';\nimport abs from '@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 ( isRowMajor( order ) ) {\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\nexport default 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\nimport bufferCtors from '@stdlib/ndarray-base-buffer-ctors';\nimport allocUnsafe from '@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\nexport default castBuffer;\n"],"names":["isArrayLikeObject","value","length","isInteger","PINF","copyView","arr","dtype","x","ndarray","getDType","getData","getShape","getStrides","getOffset","getOrder","len","out","i","push","iget","generic","allocUnsafe","binary","set","fcn","o","bufferCtors","arraylike2object","accessorProtocol","accessors","castReturn","complexCtors","typed","defaults","casting","settings","get","copy","flatten","mode","ndmin","order","readonly","array","options","strides","buffer","offset","btype","shape","ndims","nopts","opts","osh","FLG","arguments","isObject","TypeError","format","hasOwnProp","isndarrayLike","getBufferDType","isCastingMode","isBoolean","isNonNegativeInteger","isDataType","isAllowedCast","Error","strides2order","isOrder","submode","numel","isArray","arrayShape","expandShape","RangeError","N","s","j","isRowMajor","abs","expandStrides","isColumnMajor","ctor","castBuffer","createBuffer","shape2strides","strides2offset"],"mappings":"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"} \ No newline at end of file diff --git a/lib/cast_buffer.js b/lib/cast_buffer.js deleted file mode 100644 index fcb2d7b..0000000 --- a/lib/cast_buffer.js +++ /dev/null @@ -1,70 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var bufferCtors = require( '@stdlib/ndarray-base-buffer-ctors' ); -var allocUnsafe = require( '@stdlib/buffer-alloc-unsafe' ); - - -// MAIN // - -/** -* Casts buffer elements by copying those elements to a buffer of another data type. -* -* @private -* @param {(Array|TypedArray|Buffer)} buffer - input buffer -* @param {NonNegativeInteger} len - number of elements to cast -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output buffer -* -* @example -* var b = castBuffer( [ 1.0, 2.0, 3.0 ], 3, 'float64' ); -* // returns [ 1.0, 2.0, 3.0 ] -*/ -function castBuffer( buffer, len, dtype ) { - var ctor; - var out; - var i; - - ctor = bufferCtors( dtype ); - if ( dtype === 'generic' ) { - out = []; - for ( i = 0; i < len; i++ ) { - out.push( buffer[ i ] ); - } - } else if ( dtype === 'binary' ) { - out = allocUnsafe( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; - } - } else { - out = new ctor( len ); - for ( i = 0; i < len; i++ ) { - out[ i ] = buffer[ i ]; // TODO: wrap and use accessors here and above - } - } - return out; -} - - -// EXPORTS // - -module.exports = castBuffer; diff --git a/lib/copy_view.js b/lib/copy_view.js deleted file mode 100644 index 652249a..0000000 --- a/lib/copy_view.js +++ /dev/null @@ -1,167 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// 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 // - -/** -* Copies a "generic" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function generic( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = []; - for ( i = 0; i < len; i++ ) { - out.push( arr.iget( i ) ); // as output buffer is generic, should work with both real- and complex-valued ndarrays - } - return out; -} - -/** -* Copies a "binary" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @returns {Array} output data buffer -*/ -function binary( arr ) { - var len; - var out; - var i; - - len = arr.length; - out = allocUnsafe( len ); - 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 a complex-valued ndarray to a "binary" ndarray or a double-precision floating-point ndarray to binary, etc) - } - return out; -} - -/** -* Copies a "typed" ndarray view. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {Array} output data buffer -*/ -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 ); - - // 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 ); - } -} - - -// MAIN // - -/** -* Copies an ndarray view to a data buffer. -* -* @private -* @param {ndarray} arr - input ndarray -* @param {string} dtype - data type -* @returns {(Array|TypedArray|Buffer)} output data buffer -* -* @example -* var ndarray = require( '@stdlib/ndarray-ctor' ); -* -* var buffer = [ 1.0, 2.0, 3.0 ]; -* var shape = [ 3 ]; -* var strides = [ -1 ]; -* var vec = ndarray( 'generic', buffer, shape, strides, 2, 'row-major' ); -* -* var b = copyView( vec, 'float64' ); -* // returns [ 3.0, 2.0, 1.0 ] -*/ -function copyView( arr, dtype ) { - 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( x ); - } - if ( dtype === 'binary' ) { - return binary( x ); - } - return typed( x, dtype ); -} - - -// EXPORTS // - -module.exports = copyView; diff --git a/lib/defaults.js b/lib/defaults.js deleted file mode 100644 index 53addb7..0000000 --- a/lib/defaults.js +++ /dev/null @@ -1,54 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var settings = require( '@stdlib/ndarray-defaults' ); - - -// MAIN // - -/** -* Returns default options. -* -* @private -* @returns {Object} default options -* -* @example -* var o = defaults(); -* // returns {...} -*/ -function defaults() { - return { - 'casting': settings.get( 'casting' ), - 'copy': false, - 'dtype': settings.get( 'dtypes.default' ), - 'flatten': true, - 'mode': settings.get( 'index_mode' ), - 'ndmin': 0, - 'order': settings.get( 'order' ), - 'readonly': false - }; -} - - -// EXPORTS // - -module.exports = defaults; diff --git a/lib/expand_shape.js b/lib/expand_shape.js deleted file mode 100644 index fb76988..0000000 --- a/lib/expand_shape.js +++ /dev/null @@ -1,49 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MAIN // - -/** -* Prepends singleton dimensions in order to satisfy a minimum number of dimensions. -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - array dimensions -* @param {NonNegativeInteger} ndmin - minimum number of dimensions -* @returns {Array} output shape array -*/ -function expandShape( ndims, shape, ndmin ) { - var out; - var i; - - out = []; - for ( i = 0; i < ndmin-ndims; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < ndims; i++ ) { - out.push( shape[ i ] ); - } - return out; -} - - -// EXPORTS // - -module.exports = expandShape; diff --git a/lib/expand_strides.js b/lib/expand_strides.js deleted file mode 100644 index 5b7cd5e..0000000 --- a/lib/expand_strides.js +++ /dev/null @@ -1,79 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var isRowMajor = require( '@stdlib/ndarray-base-assert-is-row-major-string' ); -var abs = require( '@stdlib/math-base-special-abs' ); - - -// MAIN // - -/** -* Expands a strides array to accommodate an expanded array shape (i.e., an array shape with prepended singleton dimensions). -* -* @private -* @param {NonNegativeInteger} ndims - number of dimensions -* @param {Array} shape - expanded array shape -* @param {Array} strides - strides array -* @param {string} order - memory layout order -* @returns {Array} output strides array -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 1, 2 ], 'column-major' ); -* // returns [ 1, 1, 1, 2 ] -* -* @example -* var out = expandStrides( 4, [ 1, 1, 2, 2 ], [ 2, 1 ], 'row-major' ); -* // returns [ 4, 4, 2, 1 ] -*/ -function expandStrides( ndims, shape, strides, order ) { - var out; - var N; - var s; - var i; - var j; - - N = strides.length; - j = ndims - N; - out = []; - if ( isRowMajor( order ) ) { - s = abs( strides[ 0 ] ) * shape[ j ]; // at `j` is the size of the first non-prepended dimension - for ( i = 0; i < j; i++ ) { - out.push( s ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } else { // column-major - for ( i = 0; i < j; i++ ) { - out.push( 1 ); - } - for ( i = 0; i < N; i++ ) { - out.push( strides[ i ] ); - } - } - return out; -} - - -// EXPORTS // - -module.exports = expandStrides; diff --git a/lib/index.js b/lib/index.js deleted file mode 100644 index a50866a..0000000 --- a/lib/index.js +++ /dev/null @@ -1,71 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -/** -* Multidimensional array. -* -* @module @stdlib/ndarray-array -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* var array = require( '@stdlib/ndarray-array' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ - -// MODULES // - -var main = require( './main.js' ); - - -// EXPORTS // - -module.exports = main; diff --git a/lib/is_array_like_object.js b/lib/is_array_like_object.js deleted file mode 100644 index 7f25d41..0000000 --- a/lib/is_array_like_object.js +++ /dev/null @@ -1,58 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var PINF = require( '@stdlib/constants-float64-pinf' ); -var isInteger = require( '@stdlib/math-base-assert-is-integer' ); - - -// MAIN // - -/** -* Tests (loosely) if an input value is an array-like object. -* -* @private -* @param {*} value - value to test -* @returns {boolean} boolean indicating if an input value is an array-like object -* -* @example -* var bool = isArrayLikeObject( [] ); -* // returns true -* -* @example -* var bool = isArrayLikeObject( '' ); -* // returns false -*/ -function isArrayLikeObject( value ) { - return ( - typeof value === 'object' && - value !== null && - typeof value.length === 'number' && - isInteger( value.length ) && - value.length >= 0 && - value.length < PINF - ); -} - - -// EXPORTS // - -module.exports = isArrayLikeObject; diff --git a/lib/main.js b/lib/main.js deleted file mode 100644 index 88dcbce..0000000 --- a/lib/main.js +++ /dev/null @@ -1,347 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var hasOwnProp = require( '@stdlib/assert-has-own-property' ); -var isObject = require( '@stdlib/assert-is-plain-object' ); -var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive; -var isArray = require( '@stdlib/assert-is-array' ); -var isNonNegativeInteger = require( '@stdlib/assert-is-nonnegative-integer' ).isPrimitive; -var isndarrayLike = require( '@stdlib/assert-is-ndarray-like' ); -var shape2strides = require( '@stdlib/ndarray-base-shape2strides' ); -var strides2offset = require( '@stdlib/ndarray-base-strides2offset' ); -var strides2order = require( '@stdlib/ndarray-base-strides2order' ); -var numel = require( '@stdlib/ndarray-base-numel' ); -var ndarray = require( '@stdlib/ndarray-ctor' ); -var isColumnMajor = require( '@stdlib/ndarray-base-assert-is-column-major-string' ); -var isDataType = require( '@stdlib/ndarray-base-assert-is-data-type' ); -var isOrder = require( '@stdlib/ndarray-base-assert-is-order' ); -var isCastingMode = require( '@stdlib/ndarray-base-assert-is-casting-mode' ); -var isAllowedCast = require( '@stdlib/ndarray-base-assert-is-allowed-data-type-cast' ); -var createBuffer = require( '@stdlib/ndarray-base-buffer' ); -var getBufferDType = require( '@stdlib/ndarray-base-buffer-dtype' ); -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' ); -var arrayShape = require( '@stdlib/array-shape' ); -var flatten = require( '@stdlib/array-base-flatten' ); -var format = require( '@stdlib/error-tools-fmtprodmsg' ); -var isArrayLikeObject = require( './is_array_like_object.js' ); -var getDefaults = require( './defaults.js' ); -var castBuffer = require( './cast_buffer.js' ); -var copyView = require( './copy_view.js' ); -var expandShape = require( './expand_shape.js' ); -var expandStrides = require( './expand_strides.js' ); - - -// VARIABLES // - -var defaults = getDefaults(); - - -// MAIN // - -/** -* Returns a multidimensional array. -* -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [buffer] - data source -* @param {Options} [options] - function options -* @param {(ArrayLikeObject|TypedArrayLike|Buffer|ndarrayLike)} [options.buffer] - data source -* @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) -* @param {string} [options.order="row-major"] - specifies the memory layout of the array as either row-major (C-style) or column-major (Fortran-style) -* @param {NonNegativeIntegerArray} [options.shape] - array shape -* @param {string} [options.mode="throw"] - specifies how to handle indices which exceed array dimensions -* @param {StringArray} [options.submode=["throw"]] - specifies how to handle subscripts which exceed array dimensions on a per dimension basis -* @param {boolean} [options.copy=false] - boolean indicating whether to copy source data to a new data buffer -* @param {boolean} [options.flatten=true] - boolean indicating whether to automatically flatten generic array data sources -* @param {NonNegativeInteger} [options.ndmin=0] - minimum number of dimensions -* @param {string} [options.casting="safe"] - casting rule used to determine what constitutes an acceptable cast -* @param {boolean} [options.readonly=false] - boolean indicating if an array should be read-only -* @throws {TypeError} options argument must be an object -* @throws {TypeError} must provide valid options -* @throws {Error} must provide either an array shape, data source, or both -* @throws {Error} invalid cast -* @throws {RangeError} data source must be compatible with specified meta data -* @returns {ndarray} ndarray instance -* -* @example -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ] ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1 -* -* @example -* var opts = { -* 'dtype': 'generic', -* 'flatten': false -* }; -* -* var arr = array( [ [ 1, 2 ], [ 3, 4 ] ], opts ); -* // returns -* -* var v = arr.get( 0 ); -* // returns [ 1, 2 ] -* -* @example -* var Float64Array = require( '@stdlib/array-float64' ); -* -* var opts = { -* 'shape': [ 2, 2 ] -* }; -* -* var arr = array( new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ), opts ); -* // returns -* -* var v = arr.get( 0, 0 ); -* // returns 1.0 -*/ -function array() { - var options; - var strides; - var buffer; - var offset; - var order; - var dtype; - var btype; - var shape; - var ndims; - var nopts; - var opts; - var osh; - var len; - var ord; - var FLG; - - if ( arguments.length === 1 ) { - if ( isArrayLikeObject( arguments[ 0 ] ) ) { - buffer = arguments[ 0 ]; - options = {}; - } else { - options = arguments[ 0 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT56', options ) ); - } - if ( hasOwnProp( options, 'buffer' ) ) { - buffer = options.buffer; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT57', 'buffer', buffer ) ); - } - } - } - } else { - buffer = arguments[ 0 ]; - if ( !isArrayLikeObject( buffer ) ) { // weak test - throw new TypeError( format( '0hT58', buffer ) ); - } - options = arguments[ 1 ]; - if ( !isObject( options ) ) { - throw new TypeError( format( '0hT2V', options ) ); - } - // Note: we ignore whether `options` has a `buffer` property - } - if ( buffer ) { - if ( isndarrayLike( buffer ) ) { - btype = getDType( buffer ); - FLG = true; - } else { - btype = getBufferDType( buffer ) || 'generic'; // fallback to a "generic" dtype when provided, e.g., a generic accessor array as a data source - FLG = false; - } - } - nopts = {}; - opts = {}; - - // Validate some options before others... - if ( hasOwnProp( options, 'casting' ) ) { - opts.casting = options.casting; - if ( !isCastingMode( opts.casting ) ) { - throw new TypeError( format( '0hT59', 'casting', opts.casting ) ); - } - } else { - opts.casting = defaults.casting; - } - if ( hasOwnProp( options, 'flatten' ) ) { - opts.flatten = options.flatten; - if ( !isBoolean( opts.flatten ) ) { - throw new TypeError( format( '0hT2o', 'flatten', opts.flatten ) ); - } - } else { - opts.flatten = defaults.flatten; - } - if ( hasOwnProp( options, 'ndmin' ) ) { - opts.ndmin = options.ndmin; - if ( !isNonNegativeInteger( opts.ndmin ) ) { - throw new TypeError( format( '0hT2t', 'ndmin', opts.ndmin ) ); - } - // 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) - } else { - opts.ndmin = defaults.ndmin; - } - - // Validate the remaining options... - if ( hasOwnProp( options, 'dtype' ) ) { - dtype = options.dtype; - if ( !isDataType( dtype ) ) { - throw new TypeError( format( '0hTBf', 'dtype', dtype ) ); - } - if ( btype && !isAllowedCast( btype, dtype, opts.casting ) ) { - throw new Error( format( '0hT5B', opts.casting, btype, dtype ) ); - } - } else if ( btype ) { // btype !== void 0 - // 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. - - // Only cast generic array data sources when not provided an ndarray... - if ( !FLG && btype === 'generic' ) { - dtype = defaults.dtype; - } else { - dtype = btype; - } - } else { - dtype = defaults.dtype; - } - if ( hasOwnProp( options, 'order' ) ) { - order = options.order; - if ( order === 'any' || order === 'same' ) { - if ( FLG ) { - // 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.... - if ( order === 'any' ) { - // Compute the layout order in order to ascertain whether an ndarray can be considered both "row-major" and "column-major": - ord = strides2order( getStrides( buffer ) ); - - // 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... - if ( ord === 3 ) { - order = defaults.order; - } else { - order = getOrder( buffer ); - } - } - // Otherwise, use the same order as the provided ndarray... - else if ( order === 'same' ) { - order = getOrder( buffer ); - } - } else { - order = defaults.order; - } - } else if ( !isOrder( order ) ) { - throw new TypeError( format( '0hT5C', 'order', order ) ); - } - } else { - order = defaults.order; - } - if ( hasOwnProp( options, 'mode' ) ) { - nopts.mode = options.mode; - } else { - nopts.mode = defaults.mode; - } - if ( hasOwnProp( options, 'submode' ) ) { - nopts.submode = options.submode; - } else { - nopts.submode = [ nopts.mode ]; - } - if ( hasOwnProp( options, 'readonly' ) ) { - nopts.readonly = options.readonly; - } else { - nopts.readonly = defaults.readonly; - } - if ( hasOwnProp( options, 'copy' ) ) { - opts.copy = options.copy; - if ( !isBoolean( opts.copy ) ) { - throw new TypeError( format( '0hT2o', 'copy', opts.copy ) ); - } - } else { - opts.copy = defaults.copy; - } - // If not provided a shape, infer from a provided data source... - if ( hasOwnProp( options, 'shape' ) ) { - shape = options.shape; - if ( !isArrayLikeObject( shape ) ) { // weak test - throw new TypeError( format( '0hT5D', 'shape', shape ) ); - } - ndims = shape.length; - len = numel( shape ); - } else if ( buffer ) { - if ( FLG ) { - shape = getShape( buffer ); - ndims = shape.length; - len = numel( shape ); - } else if ( opts.flatten && isArray( buffer ) ) { - shape = arrayShape( buffer ); - osh = shape; // cache a reference to the inferred shape - ndims = shape.length; - len = numel( shape ); - } else { - ndims = 1; - len = buffer.length; - shape = [ len ]; // assume a 1-dimensional array (vector) - } - } else { - throw new Error( format('0hT0X') ); - } - // Adjust the array shape to satisfy the minimum number of dimensions... - if ( ndims < opts.ndmin ) { - shape = expandShape( ndims, shape, opts.ndmin ); - ndims = opts.ndmin; - } - // 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... - if ( FLG ) { - if ( numel( buffer.shape ) !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = copyView( buffer, dtype ); - } else { - strides = getStrides( buffer ); - offset = getOffset( buffer ); - buffer = getData( buffer ); - if ( strides.length < ndims ) { - // Account for augmented dimensions (note: expanding the strides array to account for prepended singleton dimensions does **not** affect the index offset): - strides = expandStrides( ndims, shape, strides, order ); - } - } - } else if ( buffer ) { - if ( btype === 'generic' && opts.flatten && isArray( buffer ) ) { - buffer = flatten( buffer, osh || arrayShape( buffer ), isColumnMajor( order ) ); - } - if ( buffer.length !== len ) { - throw new RangeError( format('0hT0Y') ); - } - if ( btype !== dtype || opts.copy ) { - buffer = castBuffer( buffer, len, dtype ); - } - } else { - buffer = createBuffer( dtype, len ); - } - // 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... - if ( strides === void 0 ) { - strides = shape2strides( shape, order ); - offset = strides2offset( shape, strides ); - } - return new ndarray( dtype, buffer, shape, strides, offset, order, nopts ); -} - - -// EXPORTS // - -module.exports = array; diff --git a/package.json b/package.json index 573f317..f54964a 100644 --- a/package.json +++ b/package.json @@ -3,31 +3,8 @@ "version": "0.2.1", "description": "Multidimensional arrays.", "license": "Apache-2.0", - "author": { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": { - "test": "make test", - "test-cov": "make test-cov", - "examples": "make examples", - "benchmark": "make benchmark" - }, + "type": "module", + "main": "./index.mjs", "homepage": "https://stdlib.io", "repository": { "type": "git", @@ -36,70 +13,6 @@ "bugs": { "url": "https://github.com/stdlib-js/stdlib/issues" }, - "dependencies": { - "@stdlib/array-base-arraylike2object": "^0.2.1", - "@stdlib/array-base-flatten": "^0.2.1", - "@stdlib/array-shape": "^0.2.2", - "@stdlib/assert-has-own-property": "^0.2.2", - "@stdlib/assert-is-array": "^0.2.2", - "@stdlib/assert-is-boolean": "^0.2.2", - "@stdlib/assert-is-ndarray-like": "^0.2.2", - "@stdlib/assert-is-nonnegative-integer": "^0.2.2", - "@stdlib/assert-is-plain-object": "^0.2.2", - "@stdlib/buffer-alloc-unsafe": "^0.2.2", - "@stdlib/complex-base-cast-return": "^0.2.2", - "@stdlib/complex-ctors": "^0.2.2", - "@stdlib/constants-float64-pinf": "^0.2.2", - "@stdlib/math-base-assert-is-integer": "^0.2.5", - "@stdlib/math-base-special-abs": "^0.2.2", - "@stdlib/ndarray-base-assert-is-allowed-data-type-cast": "^0.2.2", - "@stdlib/ndarray-base-assert-is-casting-mode": "^0.2.2", - "@stdlib/ndarray-base-assert-is-column-major-string": "github:stdlib-js/ndarray-base-assert-is-column-major-string#main", - "@stdlib/ndarray-base-assert-is-data-type": "^0.2.2", - "@stdlib/ndarray-base-assert-is-order": "^0.2.2", - "@stdlib/ndarray-base-assert-is-row-major-string": "github:stdlib-js/ndarray-base-assert-is-row-major-string#main", - "@stdlib/ndarray-base-buffer": "^0.3.0", - "@stdlib/ndarray-base-buffer-ctors": "^0.3.0", - "@stdlib/ndarray-base-buffer-dtype": "^0.3.0", - "@stdlib/ndarray-base-ctor": "^0.2.2", - "@stdlib/ndarray-base-numel": "^0.2.2", - "@stdlib/ndarray-base-shape2strides": "^0.2.2", - "@stdlib/ndarray-base-strides2offset": "^0.2.2", - "@stdlib/ndarray-base-strides2order": "^0.2.2", - "@stdlib/ndarray-ctor": "^0.2.2", - "@stdlib/ndarray-data-buffer": "^0.2.2", - "@stdlib/ndarray-defaults": "^0.3.0", - "@stdlib/ndarray-dtype": "^0.2.2", - "@stdlib/ndarray-offset": "^0.2.2", - "@stdlib/ndarray-order": "^0.2.2", - "@stdlib/ndarray-shape": "^0.2.2", - "@stdlib/ndarray-strides": "^0.2.2", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2", - "@stdlib/types": "^0.4.3", - "@stdlib/error-tools-fmtprodmsg": "^0.2.2" - }, - "devDependencies": { - "@stdlib/array-float32": "^0.2.2", - "tape": "git+https://github.com/kgryte/tape.git#fix/globby", - "istanbul": "^0.4.1", - "tap-min": "git+https://github.com/Planeshifter/tap-min.git", - "@stdlib/bench-harness": "^0.2.2" - }, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], "keywords": [ "stdlib", "stdtypes", @@ -116,7 +29,6 @@ "numpy.array", "numpy.asarray" ], - "__stdlib__": {}, "funding": { "type": "opencollective", "url": "https://opencollective.com/stdlib" diff --git a/stats.html b/stats.html new file mode 100644 index 0000000..5392f02 --- /dev/null +++ b/stats.html @@ -0,0 +1,4842 @@ + + + + + + + + Rollup Visualizer + + + +
+ + + + + diff --git a/test/dist/test.js b/test/dist/test.js deleted file mode 100644 index a8a9c60..0000000 --- a/test/dist/test.js +++ /dev/null @@ -1,33 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2023 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var main = require( './../../dist' ); - - -// TESTS // - -tape( 'main export is defined', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( main !== void 0, true, 'main export is defined' ); - t.end(); -}); diff --git a/test/test.js b/test/test.js deleted file mode 100644 index ca4a494..0000000 --- a/test/test.js +++ /dev/null @@ -1,126 +0,0 @@ -/** -* @license Apache-2.0 -* -* Copyright (c) 2018 The Stdlib Authors. -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ - -'use strict'; - -// MODULES // - -var tape = require( 'tape' ); -var ndarray = require( './../lib' ); - - -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof ndarray, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { - var values; - var i; - - values = [ - '5', - 5, - NaN, - true, - false, - null, - void 0, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if not provided either a `shape` or `buffer` option', function test( t ) { - t.throws( badValue( {} ), Error, 'throws an error when not provided either a `shape` or `buffer` option' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -tape( 'the function throws an error if provided an invalid option', function test( t ) { - var values; - var i; - - values = [ - '5', - 'beep', - 'boop', - 'foo', - 'bar', - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[ i ] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - var opts = { - 'shape': [ 3, 2 ], - 'dtype': value - }; - ndarray( opts ); - }; - } -}); - -tape( 'the function throws an error if provided a `shape` option which is incompatible with a provided buffer', function test( t ) { - var opts = { - 'dtype': 'generic', - 'shape': [ 3, 3 ], - 'buffer': [ 1, 2, 3, 4, 5, 6 ] - }; - t.throws( badValue( opts ), Error, 'throws an error when provided incompatible `shape` and `buffer` options' ); - t.end(); - - function badValue( value ) { - return function badValue() { - ndarray( value ); - }; - } -}); - -// TODO: tests