@stdlib/ndarray-base-broadcast-array 0.2.2 → 0.2.4

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-2024 The Stdlib Authors.
1
+ Copyright (c) 2016-2026 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-2024. The Stdlib [Authors][stdlib-authors].
187
+ Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
188
188
 
189
189
  </section>
190
190
 
@@ -197,8 +197,8 @@ Copyright &copy; 2016-2024. 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.2.2
201
- [test-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml?query=branch:v0.2.2
200
+ [test-image]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml/badge.svg?branch=v0.2.4
201
+ [test-url]: https://github.com/stdlib-js/ndarray-base-broadcast-array/actions/workflows/test.yml?query=branch:v0.2.4
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
@@ -210,8 +210,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
210
210
 
211
211
  -->
212
212
 
213
- [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
214
- [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
213
+ [chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
214
+ [chat-url]: https://stdlib.zulipchat.com
215
215
 
216
216
  [stdlib]: https://github.com/stdlib-js/stdlib
217
217
 
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
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){"use strict";var t=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),p=require("@stdlib/string-format");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("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.");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("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.",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("invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.",t(s).join(", "),t(r).join(", "),e))}return g(w(a),D(a),t(r),i,q(a),b(a))}f.exports=j});var A=c();module.exports=A;
1
+ "use strict";var m=function(a,e){return function(){return e||a((e={exports:{}}).exports,e),e.exports}};var f=m(function(x,c){"use strict";var n=require("@stdlib/array-base-copy-indexed"),g=require("@stdlib/ndarray-base-ctor"),l=require("@stdlib/ndarray-base-shape"),y=require("@stdlib/ndarray-base-strides"),q=require("@stdlib/ndarray-base-offset"),b=require("@stdlib/ndarray-base-order"),w=require("@stdlib/ndarray-base-dtype"),D=require("@stdlib/ndarray-base-data-buffer"),j=require("@stdlib/array-base-zeros"),p=require("@stdlib/string-format");function A(a,e){var t,o,i,u,s,h,d,r,v;if(s=e.length,i=l(a,!1),h=i.length,s<h)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.");for(t=j(s),u=y(a,!1),r=s-1;r>=0;r--)if(v=h-s+r,!(v<0)){if(d=i[v],o=e[r],o!==0&&o<d)throw new Error(p("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.",n(i).join(", "),n(e).join(", "),r));if(d===o)t[r]=u[v];else if(d===1)t[r]=0;else throw new Error(p("invalid argument. Input array and the specified shape are broadcast incompatible. Array shape: (%s). Desired shape: (%s). Dimension: %u.",n(i).join(", "),n(e).join(", "),r))}return g(w(a),D(a),n(e),t,q(a),b(a))}c.exports=A});var z=f();module.exports=z;
2
2
  /**
3
3
  * @license Apache-2.0
4
4
  *
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 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"]
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 zeros = require( '@stdlib/array-base-zeros' );\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 = zeros( N );\n\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,QAAS,8BAA+B,EACrDC,EAAY,QAAS,6BAA8B,EACnDC,EAAW,QAAS,4BAA6B,EACjDC,EAAW,QAAS,4BAA6B,EACjDC,EAAU,QAAS,kCAAmC,EACtDC,EAAQ,QAAS,0BAA2B,EAC5CC,EAAS,QAAS,uBAAwB,EA6D9C,SAASC,EAAgBC,EAAKC,EAAQ,CACrC,IAAIC,EACAC,EACAC,EACAC,EACAC,EACAC,EACA,EACAC,EACAC,EAKJ,GAHAH,EAAIL,EAAM,OACVG,EAAKb,EAAUS,EAAK,EAAM,EAC1BO,EAAIH,EAAG,OACFE,EAAIC,EACR,MAAM,IAAI,MAAO,8JAA+J,EAOjL,IAJAL,EAAUL,EAAOS,CAAE,EAGnBD,EAAKb,EAAYQ,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+PT,EAAMe,CAAG,EAAE,KAAM,IAAK,EAAGf,EAAMY,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,2IAA4IT,EAAMe,CAAG,EAAE,KAAM,IAAK,EAAGf,EAAMY,CAAM,EAAE,KAAM,IAAK,EAAGO,CAAE,CAAE,EAGhO,OAAOlB,EAASK,EAAUK,CAAI,EAAGJ,EAASI,CAAI,EAAGX,EAAMY,CAAM,EAAGC,EAAST,EAAWO,CAAI,EAAGN,EAAUM,CAAI,CAAE,CAC5G,CAKAZ,EAAO,QAAUW,IC/EjB,IAAIW,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "copy", "ndarray", "getShape", "getStrides", "getOffset", "getOrder", "getDType", "getData", "zeros", "format", "broadcastArray", "arr", "shape", "strides", "dim", "sh", "st", "N", "M", "i", "j", "main"]
7
7
  }
package/lib/main.js CHANGED
@@ -23,11 +23,12 @@
23
23
  var copy = require( '@stdlib/array-base-copy-indexed' );
24
24
  var ndarray = require( '@stdlib/ndarray-base-ctor' );
25
25
  var getShape = require( '@stdlib/ndarray-base-shape' );
26
- var getStrides = require('@stdlib/ndarray-base-strides' );
26
+ var getStrides = require( '@stdlib/ndarray-base-strides' );
27
27
  var getOffset = require( '@stdlib/ndarray-base-offset' );
28
28
  var getOrder = require( '@stdlib/ndarray-base-order' );
29
29
  var getDType = require( '@stdlib/ndarray-base-dtype' );
30
30
  var getData = require( '@stdlib/ndarray-base-data-buffer' );
31
+ var zeros = require( '@stdlib/array-base-zeros' );
31
32
  var format = require( '@stdlib/string-format' );
32
33
 
33
34
 
@@ -106,11 +107,9 @@ function broadcastArray( arr, shape ) {
106
107
  if ( N < M ) {
107
108
  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.' );
108
109
  }
109
- // Initialize a strides array...
110
- strides = [];
111
- for ( i = 0; i < N; i++ ) {
112
- strides.push( 0 );
113
- }
110
+ // Initialize a strides array:
111
+ strides = zeros( N );
112
+
114
113
  // Determine the output array strides...
115
114
  st = getStrides( arr, false );
116
115
  for ( i = N-1; i >= 0; i-- ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-broadcast-array",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "Broadcast an ndarray to a specified shape.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -30,16 +30,17 @@
30
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@stdlib/array-base-copy-indexed": "^0.2.1",
34
- "@stdlib/ndarray-base-ctor": "^0.2.2",
35
- "@stdlib/ndarray-base-data-buffer": "^0.2.2",
36
- "@stdlib/ndarray-base-dtype": "^0.2.2",
37
- "@stdlib/ndarray-base-offset": "^0.2.2",
38
- "@stdlib/ndarray-base-order": "^0.2.2",
39
- "@stdlib/ndarray-base-shape": "^0.2.1",
40
- "@stdlib/ndarray-base-strides": "^0.2.1",
41
- "@stdlib/string-format": "^0.2.2",
42
- "@stdlib/error-tools-fmtprodmsg": "^0.2.2"
33
+ "@stdlib/array-base-copy-indexed": "^0.2.3",
34
+ "@stdlib/array-base-zeros": "^0.2.3",
35
+ "@stdlib/ndarray-base-ctor": "^0.3.1",
36
+ "@stdlib/ndarray-base-data-buffer": "^0.2.3",
37
+ "@stdlib/ndarray-base-dtype": "^0.2.3",
38
+ "@stdlib/ndarray-base-offset": "^0.2.3",
39
+ "@stdlib/ndarray-base-order": "^0.2.3",
40
+ "@stdlib/ndarray-base-shape": "^0.2.3",
41
+ "@stdlib/ndarray-base-strides": "^0.2.3",
42
+ "@stdlib/string-format": "^0.2.3",
43
+ "@stdlib/error-tools-fmtprodmsg": "^0.2.3"
43
44
  },
44
45
  "devDependencies": {},
45
46
  "engines": {
@@ -73,7 +74,6 @@
73
74
  "utils",
74
75
  "util"
75
76
  ],
76
- "__stdlib__": {},
77
77
  "funding": {
78
78
  "type": "opencollective",
79
79
  "url": "https://opencollective.com/stdlib"