@stdlib/ndarray-base-broadcast-array 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -1 +1 @@
1
- Copyright (c) 2016-2023 The Stdlib Authors.
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md CHANGED
@@ -184,7 +184,7 @@ See [LICENSE][stdlib-license].
184
184
 
185
185
  ## Copyright
186
186
 
187
- Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
187
+ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
188
188
 
189
189
  </section>
190
190
 
@@ -197,8 +197,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
197
197
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-broadcast-array.svg
198
198
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-broadcast-array
199
199
 
200
- [test-image]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml/badge.svg?branch=v0.1.0
201
- [test-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml?query=branch:v0.1.0
200
+ [test-image]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml/badge.svg?branch=v0.2.0
201
+ [test-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml?query=branch:v0.2.0
202
202
 
203
203
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-broadcast-array/main.svg
204
204
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-broadcast-array?branch=main
@@ -221,8 +221,11 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
221
221
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
222
222
 
223
223
  [deno-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/deno
224
+ [deno-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/deno/README.md
224
225
  [umd-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/umd
226
+ [umd-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/umd/README.md
225
227
  [esm-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/tree/esm
228
+ [esm-readme]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/esm/README.md
226
229
  [branches-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/blob/main/branches.md
227
230
 
228
231
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-broadcast-array/main/LICENSE
package/SECURITY.md ADDED
@@ -0,0 +1,5 @@
1
+ # Security
2
+
3
+ > Policy for reporting security vulnerabilities.
4
+
5
+ See the security policy [in the main project repository](https://github.com/stdlib-js/stdlib/security).
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var f=m(function(w,c){
2
- var y=require('@stdlib/ndarray-base-ctor/dist'),v=require('@stdlib/error-tools-fmtprodmsg/dist'),t=require('@stdlib/array-base-copy-indexed/dist');function l(a,r){var i,o,s,u,n,p,d,e,h;if(n=r.length,s=a.shape,p=s.length,n<p)throw new Error(format('0i50Z'));for(i=[],e=0;e<n;e++)i.push(0);for(u=a.strides,e=n-1;e>=0;e--)if(h=p-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o<d)throw new Error(v('0i55F',t(s).join(", "),t(r).join(", "),e));if(d===o)i[e]=u[h];else if(d===1)i[e]=0;else throw new Error(v('0i55G',t(s).join(", "),t(r).join(", "),e))}return y(a.dtype,a.data,t(r),i,a.offset,a.order)}c.exports=l
3
- });var b=f();module.exports=b;
1
+ "use strict";var m=function(a,r){return function(){return r||a((r={exports:{}}).exports,r),r.exports}};var c=m(function(x,f){
2
+ var t=require('@stdlib/array-base-copy-indexed/dist'),g=require('@stdlib/ndarray-base-ctor/dist'),l=require('@stdlib/ndarray-base-shape/dist'),y=require('@stdlib/ndarray-base-strides/dist'),q=require('@stdlib/ndarray-base-offset/dist'),b=require('@stdlib/ndarray-base-order/dist'),w=require('@stdlib/ndarray-base-dtype/dist'),D=require('@stdlib/ndarray-base-data-buffer/dist'),p=require('@stdlib/error-tools-fmtprodmsg/dist');function j(a,r){var i,o,s,v,n,u,d,e,h;if(n=r.length,s=l(a,!1),u=s.length,n<u)throw new Error(p('0i50Z'));for(i=[],e=0;e<n;e++)i.push(0);for(v=y(a,!1),e=n-1;e>=0;e--)if(h=u-n+e,!(h<0)){if(d=s[h],o=r[e],o!==0&&o<d)throw new Error(p('0i55F',t(s).join(", "),t(r).join(", "),e));if(d===o)i[e]=v[h];else if(d===1)i[e]=0;else throw new Error(p('0i55G',t(s).join(", "),t(r).join(", "),e))}return g(w(a),D(a),t(r),i,q(a),b(a))}f.exports=j
3
+ });var A=c();module.exports=A;
4
4
  /** @license Apache-2.0 */
5
5
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../lib/main.js", "../lib/index.js"],
4
- "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar format = require( '@stdlib/string-format' );\nvar copy = require( '@stdlib/array-base-copy-indexed' );\n\n\n// MAIN //\n\n/**\n* Broadcasts an ndarray to a specified shape.\n*\n* ## Notes\n*\n* - The returned array is a view on the input array data buffer. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements.\n*\n* @param {ndarray} arr - input array\n* @param {NonNegativeIntegerArray} shape - desired shape\n* @throws {Error} input array cannot have more dimensions than the desired shape\n* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape\n* @throws {Error} input array and desired shape must be broadcast compatible\n* @returns {ndarray} broadcasted array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( x, [ 3, 2, 2 ] );\n* // returns <ndarray>\n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var y = broadcastArray( x, [ 3, 2 ] );\n* // throws <Error>\n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = arr.strides;\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( x, [ 3, 2, 2 ] );\n* // returns <ndarray>\n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
- "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAU,QAAS,2BAA4B,EAC/CC,EAAS,QAAS,uBAAwB,EAC1CC,EAAO,QAAS,iCAAkC,EA6DtD,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKJ,EAAI,MACTO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKL,EAAI,QACHQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAON,EAAQ,8PAA+PC,EAAMM,CAAG,EAAE,KAAM,IAAK,EAAGN,EAAMG,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOX,EAAQ,2IAA4IC,EAAMM,CAAG,EAAE,KAAM,IAAK,EAAGN,EAAMG,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOZ,EAASI,EAAI,MAAOA,EAAI,KAAMF,EAAMG,CAAM,EAAGC,EAASF,EAAI,OAAQA,EAAI,KAAM,CACpF,CAKAL,EAAO,QAAUI,IC1EjB,IAAIW,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "ndarray", "format", "copy", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"]
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 copy = require( '@stdlib/array-base-copy-indexed' );\nvar ndarray = require( '@stdlib/ndarray-base-ctor' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\nvar getStrides = require('@stdlib/ndarray-base-strides' );\nvar getOffset = require( '@stdlib/ndarray-base-offset' );\nvar getOrder = require( '@stdlib/ndarray-base-order' );\nvar getDType = require( '@stdlib/ndarray-base-dtype' );\nvar getData = require( '@stdlib/ndarray-base-data-buffer' );\nvar format = require( '@stdlib/string-format' );\n\n\n// MAIN //\n\n/**\n* Broadcasts an ndarray to a specified shape.\n*\n* ## Notes\n*\n* - The returned array is a view on the input array data buffer. The view is typically **not** contiguous. As more than one element of a returned view may refer to the same memory location, writing to the view may affect multiple elements. If you need to write to the returned array, copy the array before performing operations which may mutate elements.\n*\n* @param {ndarray} arr - input array\n* @param {NonNegativeIntegerArray} shape - desired shape\n* @throws {Error} input array cannot have more dimensions than the desired shape\n* @throws {Error} input array dimension sizes must be `1` or equal to the corresponding dimension in the provided shape\n* @throws {Error} input array and desired shape must be broadcast compatible\n* @returns {ndarray} broadcasted array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( x, [ 3, 2, 2 ] );\n* // returns <ndarray>\n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var y = broadcastArray( x, [ 3, 2 ] );\n* // throws <Error>\n*/\nfunction broadcastArray( arr, shape ) {\n\tvar strides;\n\tvar dim;\n\tvar sh;\n\tvar st;\n\tvar N;\n\tvar M;\n\tvar d;\n\tvar i;\n\tvar j;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\tM = sh.length;\n\tif ( N < M ) {\n\t\tthrow new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );\n\t}\n\t// Initialize a strides array...\n\tstrides = [];\n\tfor ( i = 0; i < N; i++ ) {\n\t\tstrides.push( 0 );\n\t}\n\t// Determine the output array strides...\n\tst = getStrides( arr, false );\n\tfor ( i = N-1; i >= 0; i-- ) {\n\t\tj = M - N + i;\n\t\tif ( j < 0 ) {\n\t\t\t// Prepended singleton dimension; stride is zero...\n\t\t\tcontinue;\n\t\t}\n\t\td = sh[ j ];\n\t\tdim = shape[ i ];\n\t\tif ( dim !== 0 && dim < d ) {\n\t\t\tthrow new Error( format( 'invalid argument. Input array cannot be broadcast to the specified shape, as the specified shape has a dimension whose size is less than the size of the corresponding dimension in the input array. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t\tif ( d === dim ) {\n\t\t\tstrides[ i ] = st[ j ];\n\t\t} else if ( d === 1 ) {\n\t\t\t// In order to broadcast dimensions, we set the stride for that dimension to zero...\n\t\t\tstrides[ i ] = 0;\n\t\t} else {\n\t\t\t// At this point, we know that `dim > d` and that `d` does not equal `1` (e.g., `dim=3` and `d=2`); in which case, the shapes are considered incompatible (even for desired shapes which are multiples of array dimensions, as might be desired when \"tiling\" an array; e.g., `dim=4` and `d=2`)...\n\t\t\tthrow new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );\n\t\t}\n\t}\n\treturn ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len\n}\n\n\n// EXPORTS //\n\nmodule.exports = broadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2021 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Broadcast an ndarray to a specified shape.\n*\n* @module @stdlib/ndarray-base-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var broadcastArray = require( '@stdlib/ndarray-base-broadcast-array' );\n*\n* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );\n* // returns <ndarray>\n*\n* var shx = x.shape;\n* // returns [ 2, 2 ]\n*\n* var y = broadcastArray( x, [ 3, 2, 2 ] );\n* // returns <ndarray>\n*\n* var shy = y.shape;\n* // returns [ 3, 2, 2 ]\n*\n* var v = y.get( 0, 0, 0 );\n* // returns 1\n*\n* v = y.get( 0, 0, 1 );\n* // returns 2\n*\n* v = y.get( 1, 0, 0 );\n* // returns 1\n*\n* v = y.get( 1, 1, 0 );\n* // returns 3\n*\n* v = y.get( 2, 0, 0 );\n* // returns 1\n*\n* v = y.get( 2, 1, 1 );\n* // returns 4\n*/\n\n// MODULES //\n\nvar main = require( './main.js' );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAO,QAAS,iCAAkC,EAClDC,EAAU,QAAS,2BAA4B,EAC/CC,EAAW,QAAS,4BAA6B,EACjDC,EAAa,QAAQ,8BAA+B,EACpDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKZ,EAAUQ,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAIjL,IADAL,EAAU,CAAC,EACLM,EAAI,EAAGA,EAAIF,EAAGE,IACnBN,EAAQ,KAAM,CAAE,EAIjB,IADAG,EAAKZ,EAAYO,EAAK,EAAM,EACtBQ,EAAIF,EAAE,EAAGE,GAAK,EAAGA,IAEtB,GADAC,EAAIF,EAAID,EAAIE,EACP,EAAAC,EAAI,GAMT,IAFA,EAAIL,EAAIK,CAAE,EACVN,EAAMF,EAAOO,CAAE,EACVL,IAAQ,GAAKA,EAAM,EACvB,MAAM,IAAI,MAAOL,EAAQ,8PAA+PR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAElV,GAAK,IAAML,EACVD,EAASM,CAAE,EAAIH,EAAII,CAAE,UACV,IAAM,EAEjBP,EAASM,CAAE,EAAI,MAGf,OAAM,IAAI,MAAOV,EAAQ,2IAA4IR,EAAMc,CAAG,EAAE,KAAM,IAAK,EAAGd,EAAMW,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOjB,EAASK,EAAUI,CAAI,EAAGH,EAASG,CAAI,EAAGV,EAAMW,CAAM,EAAGC,EAASR,EAAWM,CAAI,EAAGL,EAAUK,CAAI,CAAE,CAC5G,CAKAX,EAAO,QAAUU,IChFjB,IAAIW,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"]
7
7
  }
@@ -40,7 +40,7 @@ import { ndarray } from '@stdlib/types/ndarray';
40
40
  * @returns broadcasted array
41
41
  *
42
42
  * @example
43
- * var array = require( `@stdlib/ndarray/array` );
43
+ * var array = require( '@stdlib/ndarray-array' );
44
44
  *
45
45
  * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
46
46
  * // returns <ndarray>
@@ -72,7 +72,7 @@ import { ndarray } from '@stdlib/types/ndarray';
72
72
  * v = y.get( 2, 1, 1 );
73
73
  * // returns 4
74
74
  */
75
- declare function broadcastArray( arr: ndarray, shape: ArrayLike<number> ): ndarray; // tslint:disable-line:max-line-length
75
+ declare function broadcastArray( arr: ndarray, shape: ArrayLike<number> ): ndarray;
76
76
 
77
77
 
78
78
  // EXPORTS //
package/lib/main.js CHANGED
@@ -20,9 +20,15 @@
20
20
 
21
21
  // MODULES //
22
22
 
23
+ var copy = require( '@stdlib/array-base-copy-indexed' );
23
24
  var ndarray = require( '@stdlib/ndarray-base-ctor' );
25
+ var getShape = require( '@stdlib/ndarray-base-shape' );
26
+ var getStrides = require('@stdlib/ndarray-base-strides' );
27
+ var getOffset = require( '@stdlib/ndarray-base-offset' );
28
+ var getOrder = require( '@stdlib/ndarray-base-order' );
29
+ var getDType = require( '@stdlib/ndarray-base-dtype' );
30
+ var getData = require( '@stdlib/ndarray-base-data-buffer' );
24
31
  var format = require( '@stdlib/string-format' );
25
- var copy = require( '@stdlib/array-base-copy-indexed' );
26
32
 
27
33
 
28
34
  // MAIN //
@@ -95,7 +101,7 @@ function broadcastArray( arr, shape ) {
95
101
  var j;
96
102
 
97
103
  N = shape.length;
98
- sh = arr.shape;
104
+ sh = getShape( arr, false );
99
105
  M = sh.length;
100
106
  if ( N < M ) {
101
107
  throw new Error( 'invalid argument. Cannot broadcast an array to a shape having fewer dimensions. Arrays can only be broadcasted to shapes having the same or more dimensions.' );
@@ -106,7 +112,7 @@ function broadcastArray( arr, shape ) {
106
112
  strides.push( 0 );
107
113
  }
108
114
  // Determine the output array strides...
109
- st = arr.strides;
115
+ st = getStrides( arr, false );
110
116
  for ( i = N-1; i >= 0; i-- ) {
111
117
  j = M - N + i;
112
118
  if ( j < 0 ) {
@@ -128,7 +134,7 @@ function broadcastArray( arr, shape ) {
128
134
  throw new Error( format( 'invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.', copy( sh ).join( ', ' ), copy( shape ).join( ', ' ), i ) );
129
135
  }
130
136
  }
131
- return ndarray( arr.dtype, arr.data, copy( shape ), strides, arr.offset, arr.order ); // eslint-disable-line max-len
137
+ return ndarray( getDType( arr ), getData( arr ), copy( shape ), strides, getOffset( arr ), getOrder( arr ) ); // eslint-disable-line max-len
132
138
  }
133
139
 
134
140
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-broadcast-array",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Broadcast an ndarray to a specified shape.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -37,23 +37,30 @@
37
37
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@stdlib/array-base-copy-indexed": "^0.1.0",
41
- "@stdlib/ndarray-base-ctor": "^0.1.0",
42
- "@stdlib/string-format": "^0.1.0",
43
- "@stdlib/types": "^0.1.0",
44
- "@stdlib/error-tools-fmtprodmsg": "^0.1.0"
40
+ "@stdlib/array-base-copy-indexed": "^0.2.0",
41
+ "@stdlib/ndarray-base-ctor": "^0.2.0",
42
+ "@stdlib/ndarray-base-data-buffer": "^0.2.0",
43
+ "@stdlib/ndarray-base-dtype": "^0.2.0",
44
+ "@stdlib/ndarray-base-offset": "^0.2.0",
45
+ "@stdlib/ndarray-base-order": "^0.2.0",
46
+ "@stdlib/ndarray-base-shape": "^0.2.0",
47
+ "@stdlib/ndarray-base-strides": "^0.2.0",
48
+ "@stdlib/string-format": "^0.2.0",
49
+ "@stdlib/types": "^0.3.1",
50
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.0"
45
51
  },
46
52
  "devDependencies": {
47
- "@stdlib/array-float64": "^0.1.0",
48
- "@stdlib/assert-is-ndarray-like": "^0.1.0",
49
- "@stdlib/bench": "^0.1.0",
50
- "@stdlib/ndarray-array": "^0.0.9",
51
- "@stdlib/ndarray-base-numel": "^0.1.0",
52
- "@stdlib/ndarray-ctor": "^0.0.10",
53
- "@stdlib/ndarray-ind2sub": "^0.1.0",
53
+ "@stdlib/array-float64": "^0.2.0",
54
+ "@stdlib/assert-is-ndarray-like": "^0.2.0",
55
+ "@stdlib/ndarray-array": "^0.1.0",
56
+ "@stdlib/ndarray-base-numel": "^0.2.0",
57
+ "@stdlib/ndarray-ctor": "^0.1.0",
58
+ "@stdlib/ndarray-ind2sub": "^0.1.1",
54
59
  "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
55
60
  "istanbul": "^0.4.1",
56
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
61
+ "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
62
+ "@stdlib/bench-harness": "^0.2.0",
63
+ "@stdlib/bench": "^0.3.1"
57
64
  },
58
65
  "engines": {
59
66
  "node": ">=0.10.0",
package/CITATION.cff DELETED
@@ -1,30 +0,0 @@
1
- cff-version: 1.2.0
2
- title: stdlib
3
- message: >-
4
- If you use this software, please cite it using the
5
- metadata from this file.
6
-
7
- type: software
8
-
9
- authors:
10
- - name: The Stdlib Authors
11
- url: https://github.com/stdlib-js/stdlib/graphs/contributors
12
-
13
- repository-code: https://github.com/stdlib-js/stdlib
14
- url: https://stdlib.io
15
-
16
- abstract: |
17
- Standard library for JavaScript and Node.js.
18
-
19
- keywords:
20
- - JavaScript
21
- - Node.js
22
- - TypeScript
23
- - standard library
24
- - scientific computing
25
- - numerical computing
26
- - statistical computing
27
-
28
- license: Apache-2.0 AND BSL-1.0
29
-
30
- date-released: 2016