@stdlib/ndarray-base-maybe-broadcast-array 0.1.0 → 0.2.1

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
@@ -180,7 +180,7 @@ See [LICENSE][stdlib-license].
180
180
 
181
181
  ## Copyright
182
182
 
183
- Copyright © 2016-2023. The Stdlib [Authors][stdlib-authors].
183
+ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
184
184
 
185
185
  </section>
186
186
 
@@ -193,8 +193,8 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
193
193
  [npm-image]: http://img.shields.io/npm/v/@stdlib/ndarray-base-maybe-broadcast-array.svg
194
194
  [npm-url]: https://npmjs.org/package/@stdlib/ndarray-base-maybe-broadcast-array
195
195
 
196
- [test-image]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/actions/workflows/test.yml/badge.svg?branch=v0.1.0
197
- [test-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/actions/workflows/test.yml?query=branch:v0.1.0
196
+ [test-image]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/actions/workflows/test.yml/badge.svg?branch=v0.2.1
197
+ [test-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/actions/workflows/test.yml?query=branch:v0.2.1
198
198
 
199
199
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/ndarray-base-maybe-broadcast-array/main.svg
200
200
  [coverage-url]: https://codecov.io/github/stdlib-js/ndarray-base-maybe-broadcast-array?branch=main
@@ -217,8 +217,11 @@ Copyright &copy; 2016-2023. The Stdlib [Authors][stdlib-authors].
217
217
  [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
218
218
 
219
219
  [deno-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/deno
220
+ [deno-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/deno/README.md
220
221
  [umd-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/umd
222
+ [umd-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/umd/README.md
221
223
  [esm-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/tree/esm
224
+ [esm-readme]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/esm/README.md
222
225
  [branches-url]: https://github.com/stdlib-js/ndarray-base-maybe-broadcast-array/blob/main/branches.md
223
226
 
224
227
  [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/ndarray-base-maybe-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 o=function(t,r){return function(){return r||t((r={exports:{}}).exports,r),r.exports}};var s=o(function(b,a){
2
- var u=require('@stdlib/ndarray-base-broadcast-array/dist');function c(t,r){var i,n,e;if(n=r.length,i=t.shape,i.length===n){for(e=0;e<n;e++)if(i[e]!==r[e])return u(t,r);return t}return u(t,r)}a.exports=c
3
- });var v=s();module.exports=v;
1
+ "use strict";var o=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var s=o(function(l,n){
2
+ var u=require('@stdlib/ndarray-base-broadcast-array/dist'),v=require('@stdlib/ndarray-base-shape/dist');function c(e,r){var i,a,t;if(a=r.length,i=v(e,!1),i.length===a){for(t=0;t<a;t++)if(i[t]!==r[t])return u(e,r);return e}return u(e,r)}n.exports=c
3
+ });var f=s();module.exports=f;
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) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\n\n\n// MAIN //\n\n/**\n* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* ## Notes\n*\n* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray.\n* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. 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 = maybeBroadcastArray( 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 = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws <Error>\n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = arr.shape;\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-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 = maybeBroadcastArray( 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,EAAY,QAAS,sCAAuC,EA8DhE,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKF,EAAI,MAGJE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAON,EAAWE,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOF,EAAWE,EAAKC,CAAM,CAC9B,CAKAJ,EAAO,QAAUE,IChDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"]
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 broadcast = require( '@stdlib/ndarray-base-broadcast-array' );\nvar getShape = require( '@stdlib/ndarray-base-shape' );\n\n\n// MAIN //\n\n/**\n* Broadcasts an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.\n*\n* ## Notes\n*\n* - If a provided ndarray has the same shape as the specified shape, the function returns the provided ndarray.\n* - If a provided ndarray has a different (broadcast compatible) shape than the specified shape, the function returns a new (base) ndarray view of the provided ndarray's data. 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 = maybeBroadcastArray( 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 = maybeBroadcastArray( x, [ 3, 2 ] );\n* // throws <Error>\n*/\nfunction maybeBroadcastArray( arr, shape ) {\n\tvar sh;\n\tvar N;\n\tvar i;\n\n\tN = shape.length;\n\tsh = getShape( arr, false );\n\n\t// Check whether we need to broadcast the input array...\n\tif ( sh.length === N ) {\n\t\tfor ( i = 0; i < N; i++ ) {\n\t\t\t// Check whether dimensions match...\n\t\t\tif ( sh[ i ] !== shape[ i ] ) {\n\t\t\t\t// We found a mismatched dimension; delegate to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\t\t\t\treturn broadcast( arr, shape );\n\t\t\t}\n\t\t}\n\t\treturn arr;\n\t}\n\t// If we are provided an array having a different rank (i.e., number of dimensions) than the desired shape, assume we need to broadcast, delegating to `broadcast` to ensure that the input array is broadcast compatible with the desired array shape...\n\treturn broadcast( arr, shape );\n}\n\n\n// EXPORTS //\n\nmodule.exports = maybeBroadcastArray;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2022 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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 if and only if the specified shape differs from the provided ndarray's shape.\n*\n* @module @stdlib/ndarray-base-maybe-broadcast-array\n*\n* @example\n* var array = require( '@stdlib/ndarray-array' );\n* var maybeBroadcastArray = require( '@stdlib/ndarray-base-maybe-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 = maybeBroadcastArray( 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,EAAY,QAAS,sCAAuC,EAC5DC,EAAW,QAAS,4BAA6B,EA8DrD,SAASC,EAAqBC,EAAKC,EAAQ,CAC1C,IAAIC,EACAC,EACAC,EAMJ,GAJAD,EAAIF,EAAM,OACVC,EAAKJ,EAAUE,EAAK,EAAM,EAGrBE,EAAG,SAAWC,EAAI,CACtB,IAAMC,EAAI,EAAGA,EAAID,EAAGC,IAEnB,GAAKF,EAAIE,CAAE,IAAMH,EAAOG,CAAE,EAEzB,OAAOP,EAAWG,EAAKC,CAAM,EAG/B,OAAOD,CACR,CAEA,OAAOH,EAAWG,EAAKC,CAAM,CAC9B,CAKAL,EAAO,QAAUG,ICjDjB,IAAIM,EAAO,IAKX,OAAO,QAAUA",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "broadcast", "getShape", "maybeBroadcastArray", "arr", "shape", "sh", "N", "i", "main"]
7
7
  }
@@ -41,7 +41,7 @@ import { ndarray } from '@stdlib/types/ndarray';
41
41
  * @returns broadcasted array
42
42
  *
43
43
  * @example
44
- * var array = require( `@stdlib/ndarray/array` );
44
+ * var array = require( '@stdlib/ndarray-array' );
45
45
  *
46
46
  * var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
47
47
  * // returns <ndarray>
@@ -73,7 +73,7 @@ import { ndarray } from '@stdlib/types/ndarray';
73
73
  * v = y.get( 2, 1, 1 );
74
74
  * // returns 4
75
75
  */
76
- declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike<number> ): ndarray; // tslint:disable-line:max-line-length
76
+ declare function maybeBroadcastArray( arr: ndarray, shape: ArrayLike<number> ): ndarray;
77
77
 
78
78
 
79
79
  // EXPORTS //
package/lib/main.js CHANGED
@@ -21,6 +21,7 @@
21
21
  // MODULES //
22
22
 
23
23
  var broadcast = require( '@stdlib/ndarray-base-broadcast-array' );
24
+ var getShape = require( '@stdlib/ndarray-base-shape' );
24
25
 
25
26
 
26
27
  // MAIN //
@@ -88,7 +89,7 @@ function maybeBroadcastArray( arr, shape ) {
88
89
  var i;
89
90
 
90
91
  N = shape.length;
91
- sh = arr.shape;
92
+ sh = getShape( arr, false );
92
93
 
93
94
  // Check whether we need to broadcast the input array...
94
95
  if ( sh.length === N ) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stdlib/ndarray-base-maybe-broadcast-array",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Broadcast an ndarray to a specified shape if and only if the specified shape differs from the provided ndarray's shape.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -15,19 +15,12 @@
15
15
  ],
16
16
  "main": "./lib",
17
17
  "directories": {
18
- "benchmark": "./benchmark",
19
18
  "doc": "./docs",
20
- "example": "./examples",
21
19
  "lib": "./lib",
22
- "test": "./test"
20
+ "dist": "./dist"
23
21
  },
24
22
  "types": "./docs/types",
25
- "scripts": {
26
- "test": "make test",
27
- "test-cov": "make test-cov",
28
- "examples": "make examples",
29
- "benchmark": "make benchmark"
30
- },
23
+ "scripts": {},
31
24
  "homepage": "https://stdlib.io",
32
25
  "repository": {
33
26
  "type": "git",
@@ -37,22 +30,10 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/ndarray-base-broadcast-array": "^0.1.0",
41
- "@stdlib/types": "^0.1.0"
42
- },
43
- "devDependencies": {
44
- "@stdlib/array-float64": "^0.1.0",
45
- "@stdlib/assert-is-ndarray-like": "^0.1.0",
46
- "@stdlib/bench": "^0.1.0",
47
- "@stdlib/ndarray-array": "^0.0.9",
48
- "@stdlib/ndarray-base-ctor": "^0.1.0",
49
- "@stdlib/ndarray-base-numel": "^0.1.0",
50
- "@stdlib/ndarray-ctor": "^0.0.10",
51
- "@stdlib/ndarray-ind2sub": "^0.1.0",
52
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
53
- "istanbul": "^0.4.1",
54
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git"
33
+ "@stdlib/ndarray-base-broadcast-array": "^0.2.1",
34
+ "@stdlib/ndarray-base-shape": "^0.2.1"
55
35
  },
36
+ "devDependencies": {},
56
37
  "engines": {
57
38
  "node": ">=0.10.0",
58
39
  "npm": ">2.7.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