Skip to content

Commit 6098f33

Browse files
committed
Auto-generated commit
1 parent 2ca88b8 commit 6098f33

File tree

17 files changed

+1133
-4
lines changed

17 files changed

+1133
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Features
1212

13+
- [`cd23042`](https://github.com/stdlib-js/stdlib/commit/cd23042ad42089fb6b69783060bd67004d879ebe) - add `zip2views` to namespace
14+
- [`4a651c7`](https://github.com/stdlib-js/stdlib/commit/4a651c7b6d1ea9a814ac420a91c0d94de3956917) - add `array/base/zip2views`
1315
- [`302966e`](https://github.com/stdlib-js/stdlib/commit/302966e9b30769c05537f07169c2bda2fbee83f1) - add `zip` to namespace
1416
- [`e669353`](https://github.com/stdlib-js/stdlib/commit/e669353fc68d57800199dcb773accd5ce9943cef) - add `array/base/zip`
1517
- [`1626ce4`](https://github.com/stdlib-js/stdlib/commit/1626ce436f5b49949f6f49c70f351d3d25149097) - add `zip2objects` to namespace
@@ -225,6 +227,10 @@ A total of 32 issues were closed in this release:
225227

226228
<details>
227229

230+
- [`53948cc`](https://github.com/stdlib-js/stdlib/commit/53948cc063bbf85d538b84ae678c1dc5117f864b) - **docs:** fix missing variable declaration _(by Athan Reines)_
231+
- [`cd23042`](https://github.com/stdlib-js/stdlib/commit/cd23042ad42089fb6b69783060bd67004d879ebe) - **feat:** add `zip2views` to namespace _(by Athan Reines)_
232+
- [`4a651c7`](https://github.com/stdlib-js/stdlib/commit/4a651c7b6d1ea9a814ac420a91c0d94de3956917) - **feat:** add `array/base/zip2views` _(by Athan Reines)_
233+
- [`75a09fd`](https://github.com/stdlib-js/stdlib/commit/75a09fdda6729788ada783e66412521bbb03ba3e) - **docs:** update notes _(by Athan Reines)_
228234
- [`302966e`](https://github.com/stdlib-js/stdlib/commit/302966e9b30769c05537f07169c2bda2fbee83f1) - **feat:** add `zip` to namespace _(by Athan Reines)_
229235
- [`e669353`](https://github.com/stdlib-js/stdlib/commit/e669353fc68d57800199dcb773accd5ce9943cef) - **feat:** add `array/base/zip` _(by Athan Reines)_
230236
- [`73b048a`](https://github.com/stdlib-js/stdlib/commit/73b048a2cef0d2e2ab0ea10887f45fe7365c71bb) - **bench:** fix assertions _(by Athan Reines)_

base/lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1980,6 +1980,15 @@ setReadOnly( ns, 'zip2object', require( './../../base/zip2object' ) );
19801980
*/
19811981
setReadOnly( ns, 'zip2objects', require( './../../base/zip2objects' ) );
19821982

1983+
/**
1984+
* @name zip2views
1985+
* @memberof ns
1986+
* @readonly
1987+
* @type {Function}
1988+
* @see {@link module:@stdlib/array/base/zip2views}
1989+
*/
1990+
setReadOnly( ns, 'zip2views', require( './../../base/zip2views' ) );
1991+
19831992

19841993
// EXPORTS //
19851994

base/zip2objects/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The function supports the following parameters:
5656
<section class="notes">
5757

5858
- The function assumes that the list of arrays to be zipped all have the same length.
59-
- The list of provided array labels should equal the number of arrays to be zipped.
59+
- The number of provided array labels should equal the number of arrays to be zipped.
6060

6161
</section>
6262

base/zip2objects/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The function assumes that the list of arrays to be zipped all have the same
66
length.
77

8-
The list of provided array labels should equal the number of arrays to be
8+
The number of provided array labels should equal the number of arrays to be
99
zipped.
1010

1111
Parameters

base/zip2objects/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type PropertyKey = string | number | symbol;
3333
* ## Notes
3434
*
3535
* - The function assumes that the list of arrays to be zipped all have the same length.
36-
* - The list of provided array labels should equal the number of arrays to be zipped.
36+
* - The number of provided array labels should equal the number of arrays to be zipped.
3737
*
3838
* @param arrays - list of arrays to be zipped
3939
* @param labels - list of array labels

base/zip2objects/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var resolveGetter = require( './../../../base/resolve-getter' );
3131
* ## Notes
3232
*
3333
* - The function assumes that the list of arrays to be zipped all have the same length.
34-
* - The list of provided array labels should equal the number of arrays to be zipped.
34+
* - The number of provided array labels should equal the number of arrays to be zipped.
3535
*
3636
* @param {Collection<Collection>} arrays - list of arrays to be zipped
3737
* @param {ArrayLikeObject<string>} labels - list of array labels

base/zip2views/README.md

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# zip2views
22+
23+
> Zip one or more arrays to an array of composite views.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zip2views = require( '@stdlib/array/base/zip2views' );
31+
```
32+
33+
#### zip2views( arrays, labels )
34+
35+
Zips one or more arrays to an array of composite views.
36+
37+
```javascript
38+
var x = [ 1, 2, 3 ];
39+
var y = [ 'a', 'b', 'c' ];
40+
41+
var labels = [ 'x', 'y' ];
42+
43+
var z = zip2views( [ x, y ], labels );
44+
// returns [ <Object>, <Object>, <Object> ]
45+
46+
var v0 = z[ 0 ].toJSON();
47+
// returns { 'x': 1, 'y': 'a' }
48+
49+
var v1 = z[ 1 ].toJSON();
50+
// returns { 'x': 2, 'y': 'b' }
51+
52+
var v2 = z[ 2 ].toJSON();
53+
// returns { 'x': 3, 'y': 'c' }
54+
55+
// Mutate one of the input arrays:
56+
x[ 0 ] = 5;
57+
58+
v0 = z[ 0 ].toJSON();
59+
// returns { 'x': 5, 'y': 'a' }
60+
61+
// Set a view property:
62+
z[ 1 ].y = 'beep';
63+
64+
v1 = z[ 1 ].toJSON();
65+
// returns { 'x': 2, 'y': 'beep' }
66+
67+
var y1 = y.slice();
68+
// returns [ 'a', 'beep', 'c' ]
69+
```
70+
71+
The function supports the following parameters:
72+
73+
- **arrays**: list of arrays to zip.
74+
- **labels**: list of array labels.
75+
76+
Each element in the returned array is a class instance having prototype properties corresponding to the list of array labels. As demonstrated in the example above, to convert an element to a regular object, invoke an element's `toJSON` method. Note, however, that the object returned by an element's `toJSON` method no longer shares the same memory as the provided input arrays.
77+
78+
</section>
79+
80+
<!-- /.usage -->
81+
82+
<section class="notes">
83+
84+
- The function assumes that the list of arrays to be zipped all have the same length.
85+
- The number of provided array labels should equal the number of arrays to be zipped.
86+
- Each view in the returned array shares the same memory as the corresponding elements in the input arrays. Accordingly, mutation of either an input array or a view will mutate the other.
87+
88+
</section>
89+
90+
<!-- /.notes -->
91+
92+
<section class="examples">
93+
94+
## Examples
95+
96+
<!-- eslint no-undef: "error" -->
97+
98+
```javascript
99+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
100+
var zeroTo = require( '@stdlib/array/base/zero-to' );
101+
var zip2views = require( '@stdlib/array/base/zip2views' );
102+
103+
var x = zeroTo( 10 );
104+
var y = discreteUniform( x.length, -100, 100 );
105+
106+
var labels = [ 'x', 'y' ];
107+
108+
var out = zip2views( [ x, y ], labels );
109+
// returns [...]
110+
```
111+
112+
</section>
113+
114+
<!-- /.examples -->
115+
116+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
117+
118+
<section class="related">
119+
120+
</section>
121+
122+
<!-- /.related -->
123+
124+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
125+
126+
<section class="links">
127+
128+
</section>
129+
130+
<!-- /.links -->

base/zip2views/benchmark/benchmark.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isArray = require( '@stdlib/assert/is-array' );
25+
var zeroTo = require( './../../../base/zero-to' );
26+
var pkg = require( './../package.json' ).name;
27+
var zip2views = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+':len=100', function benchmark( b ) {
33+
var labels;
34+
var x;
35+
var i;
36+
var v;
37+
38+
labels = [ 'x', 'y' ];
39+
x = zeroTo( 10 );
40+
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
v = zip2views( [ x, x ], labels );
44+
if ( typeof v !== 'object' ) {
45+
b.fail( 'should return an array' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isArray( v ) ) {
50+
b.fail( 'should return an array' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
});
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var zeroTo = require( './../../../base/zero-to' );
26+
var isArray = require( '@stdlib/assert/is-array' );
27+
var pkg = require( './../package.json' ).name;
28+
var zip2views = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var labels = [ 'x', 'y' ];
42+
var x = zeroTo( len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var v;
53+
var i;
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
v = zip2views( [ x, x ], labels );
58+
if ( typeof v !== 'object' ) {
59+
b.fail( 'should return an array' );
60+
}
61+
}
62+
b.toc();
63+
if ( !isArray( v ) ) {
64+
b.fail( 'should return an array' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
}
69+
}
70+
71+
72+
// MAIN //
73+
74+
/**
75+
* Main execution sequence.
76+
*
77+
* @private
78+
*/
79+
function main() {
80+
var len;
81+
var min;
82+
var max;
83+
var f;
84+
var i;
85+
86+
min = 1; // 10^min
87+
max = 6; // 10^max
88+
89+
for ( i = min; i <= max; i++ ) {
90+
len = pow( 10, i );
91+
f = createBenchmark( len );
92+
bench( pkg+':len='+len, f );
93+
}
94+
}
95+
96+
main();

base/zip2views/docs/repl.txt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
{{alias}}( arrays, labels )
3+
Zips one or more arrays to an array of composite views.
4+
5+
The function assumes that the list of arrays to be zipped all have the same
6+
length.
7+
8+
The number of provided array labels should equal the number of arrays to be
9+
zipped.
10+
11+
Each view in the returned array shares the same memory as the corresponding
12+
elements in the input arrays. Accordingly, mutation of either an input array
13+
or a view will mutate the other.
14+
15+
Parameters
16+
----------
17+
arrays: ArrayLikeObject<ArrayLikeObject>
18+
List of arrays to zip.
19+
20+
labels: ArrayLikeObject
21+
List of array labels.
22+
23+
Returns
24+
-------
25+
out: Array<Object>
26+
Output array.
27+
28+
Examples
29+
--------
30+
> var x = [ 1, 2 ];
31+
> var y = [ 3, 4 ];
32+
> var labels = [ 'x', 'y' ];
33+
> var out = {{alias}}( [ x, y ], labels );
34+
> var v = out[ 0 ].toJSON()
35+
{ 'x': 1, 'y': 3 }
36+
> v = out[ 1 ].toJSON()
37+
{ 'x': 2, 'y': 4 }
38+
39+
See Also
40+
--------
41+

0 commit comments

Comments
 (0)