@stdlib/array-base-mskreject-map 0.0.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/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
package/NOTICE ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2016-2024 The Stdlib Authors.
package/README.md ADDED
@@ -0,0 +1,265 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2024 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
+
22
+ <details>
23
+ <summary>
24
+ About stdlib...
25
+ </summary>
26
+ <p>We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.</p>
27
+ <p>The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.</p>
28
+ <p>When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.</p>
29
+ <p>To join us in bringing numerical computing to the web, get started by checking us out on <a href="https://github.com/stdlib-js/stdlib">GitHub</a>, and please consider <a href="https://opencollective.com/stdlib">financially supporting stdlib</a>. We greatly appreciate your continued support!</p>
30
+ </details>
31
+
32
+ # mskrejectMap
33
+
34
+ [![NPM version][npm-image]][npm-url] [![Build Status][test-image]][test-url] [![Coverage Status][coverage-image]][coverage-url] <!-- [![dependencies][dependencies-image]][dependencies-url] -->
35
+
36
+ > Apply a mask to a provided input array and map the unmasked values according to a callback function.
37
+
38
+ <section class="installation">
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ npm install @stdlib/array-base-mskreject-map
44
+ ```
45
+
46
+ </section>
47
+
48
+ <section class="usage">
49
+
50
+ ## Usage
51
+
52
+ ```javascript
53
+ var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );
54
+ ```
55
+
56
+ #### mskrejectMap( x, mask, clbk\[, thisArg ] )
57
+
58
+ Returns a new array by applying a mask and mapping the unmasked values according to a callback function.
59
+
60
+ ```javascript
61
+ var x = [ 1, 2, 3, 4 ];
62
+
63
+ function clbk( val ) {
64
+ return val * 2;
65
+ }
66
+
67
+ var y = mskrejectMap( x, [ 0, 1, 0, 1 ], clbk );
68
+ // returns [ 2, 6 ]
69
+ ```
70
+
71
+ The function supports the following parameters:
72
+
73
+ - **x**: input array.
74
+ - **mask**: mask array.
75
+ - **clbk**: function to apply.
76
+ - **thisArg**: applied function execution context (_optional_).
77
+
78
+ The `clbk` function is provided three arguments:
79
+
80
+ - **value**: current unmasked array element.
81
+ - **index**: current unmasked array element index.
82
+ - **arr**: input array.
83
+
84
+ To set the `clbk` function execution context, provide a `thisArg`.
85
+
86
+ ```javascript
87
+ var x = [ 1, 2, 3, 4 ];
88
+
89
+ var mask = [ 0, 1, 0, 1 ];
90
+
91
+ var increase = 3;
92
+
93
+ function clbk( value ) {
94
+ return value + this;
95
+ }
96
+
97
+ var out = mskrejectMap( x, mask, clbk, increase );
98
+ // returns [ 4, 6 ]
99
+ ```
100
+
101
+ The function **always** returns a new "generic" array.
102
+
103
+ #### mskrejectMap.assign( x, mask, out, stride, offset, clbk\[, thisArg ] )
104
+
105
+ Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array.
106
+
107
+ ```javascript
108
+ var x = [ 1, 2, 3, 4 ];
109
+
110
+ var mask = [ 1, 0, 1, 0 ];
111
+
112
+ var out = [ 0, 0, 0, 0 ];
113
+
114
+ function clbk( val ) {
115
+ return val * 2;
116
+ }
117
+
118
+ var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk );
119
+ // returns [ 0, 8, 0, 4 ]
120
+
121
+ var bool = ( arr === out );
122
+ // returns true
123
+ ```
124
+
125
+ The function supports the following parameters:
126
+
127
+ - **x**: input array.
128
+ - **mask**: mask array.
129
+ - **out**: output array.
130
+ - **stride**: output array stride.
131
+ - **offset**: output array offset.
132
+ - **clbk**: function to apply.
133
+ - **thisArg**: applied function execution context (_optional_).
134
+
135
+ </section>
136
+
137
+ <!-- /.usage -->
138
+
139
+ <section class="notes">
140
+
141
+ ## Notes
142
+
143
+ - If a `mask` array element is falsy, the corresponding element in `x` is **mapped** in the output array; otherwise, the corresponding element in `x` is "masked" and thus **excluded** from the output array.
144
+
145
+ </section>
146
+
147
+ <!-- /.notes -->
148
+
149
+ <section class="examples">
150
+
151
+ ## Examples
152
+
153
+ <!-- eslint no-undef: "error" -->
154
+
155
+ ```javascript
156
+ var zeroTo = require( '@stdlib/array-base-zero-to' );
157
+ var bernoulli = require( '@stdlib/random-array-bernoulli' );
158
+ var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );
159
+
160
+ // Generate a linearly spaced array:
161
+ var x = zeroTo( 20 );
162
+ console.log( x );
163
+
164
+ // Generate a random mask:
165
+ var mask = bernoulli( x.length, 0.5, {
166
+ 'dtype': 'generic'
167
+ });
168
+ console.log( mask );
169
+
170
+ function clbk( val ) {
171
+ return val * 2;
172
+ }
173
+
174
+ // Filter an array using the mask:
175
+ var y = mskrejectMap( x, mask, clbk );
176
+ console.log( y );
177
+ ```
178
+
179
+ </section>
180
+
181
+ <!-- /.examples -->
182
+
183
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
184
+
185
+ <section class="related">
186
+
187
+ </section>
188
+
189
+ <!-- /.related -->
190
+
191
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
192
+
193
+
194
+ <section class="main-repo" >
195
+
196
+ * * *
197
+
198
+ ## Notice
199
+
200
+ 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.
201
+
202
+ 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].
203
+
204
+ #### Community
205
+
206
+ [![Chat][chat-image]][chat-url]
207
+
208
+ ---
209
+
210
+ ## License
211
+
212
+ See [LICENSE][stdlib-license].
213
+
214
+
215
+ ## Copyright
216
+
217
+ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
218
+
219
+ </section>
220
+
221
+ <!-- /.stdlib -->
222
+
223
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
224
+
225
+ <section class="links">
226
+
227
+ [npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-mskreject-map.svg
228
+ [npm-url]: https://npmjs.org/package/@stdlib/array-base-mskreject-map
229
+
230
+ [test-image]: https://github.com/stdlib-js/array-base-mskreject-map/actions/workflows/test.yml/badge.svg?branch=v0.0.1
231
+ [test-url]: https://github.com/stdlib-js/array-base-mskreject-map/actions/workflows/test.yml?query=branch:v0.0.1
232
+
233
+ [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-mskreject-map/main.svg
234
+ [coverage-url]: https://codecov.io/github/stdlib-js/array-base-mskreject-map?branch=main
235
+
236
+ <!--
237
+
238
+ [dependencies-image]: https://img.shields.io/david/stdlib-js/array-base-mskreject-map.svg
239
+ [dependencies-url]: https://david-dm.org/stdlib-js/array-base-mskreject-map/main
240
+
241
+ -->
242
+
243
+ [chat-image]: https://img.shields.io/gitter/room/stdlib-js/stdlib.svg
244
+ [chat-url]: https://app.gitter.im/#/room/#stdlib-js_stdlib:gitter.im
245
+
246
+ [stdlib]: https://github.com/stdlib-js/stdlib
247
+
248
+ [stdlib-authors]: https://github.com/stdlib-js/stdlib/graphs/contributors
249
+
250
+ [umd]: https://github.com/umdjs/umd
251
+ [es-module]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
252
+
253
+ [deno-url]: https://github.com/stdlib-js/array-base-mskreject-map/tree/deno
254
+ [deno-readme]: https://github.com/stdlib-js/array-base-mskreject-map/blob/deno/README.md
255
+ [umd-url]: https://github.com/stdlib-js/array-base-mskreject-map/tree/umd
256
+ [umd-readme]: https://github.com/stdlib-js/array-base-mskreject-map/blob/umd/README.md
257
+ [esm-url]: https://github.com/stdlib-js/array-base-mskreject-map/tree/esm
258
+ [esm-readme]: https://github.com/stdlib-js/array-base-mskreject-map/blob/esm/README.md
259
+ [branches-url]: https://github.com/stdlib-js/array-base-mskreject-map/blob/main/branches.md
260
+
261
+ [stdlib-license]: https://raw.githubusercontent.com/stdlib-js/array-base-mskreject-map/main/LICENSE
262
+
263
+ </section>
264
+
265
+ <!-- /.links -->
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).
@@ -0,0 +1,3 @@
1
+ /// <reference path="../docs/types/index.d.ts" />
2
+ import mskrejectMap from '../docs/types/index';
3
+ export = mskrejectMap;
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";var q=function(a,e){return function(){return e||a((e={exports:{}}).exports,e),e.exports}};var j=q(function(F,y){
2
+ var m=require('@stdlib/array-base-resolve-getter/dist');function M(a,e,t,n){var v,s,c,r;for(v=m(a),s=m(e),c=[],r=0;r<a.length;r++)s(e,r)||c.push(t.call(n,v(a,r),r,a));return c}y.exports=M
3
+ });var D=q(function(H,C){
4
+ var P=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),g=require('@stdlib/array-base-arraylike2object/dist'),h=require('@stdlib/strided-base-reinterpret-complex/dist');function O(a,e,t,n,v,s,c){var r,o;for(r=v,o=0;o<a.length;o++)e[o]||(t[r]=s.call(c,a[o],o,a),r+=n);return t}function R(a,e,t,n,v,s,c){var r,o,i,f,l,u,p,d;for(r=a.data,o=e.data,i=t.data,f=a.accessors[0],l=e.accessors[0],u=t.accessors[1],p=v,d=0;d<r.length;d++)l(o,d)||(u(i,p,s.call(c,f(r,d),d,r)),p+=n);return i}function T(a,e,t,n,v,s,c){var r,o,i,f,l,u;for(r=e.data,o=e.accessors[0],f=n*2,i=v*2,l=0;l<r.length;l++)o(r,l)||(u=l*2,t[i]=s.call(c,a[u],u,a),t[i+1]=s.call(c,a[u+1],u+1,a),i+=f);return t}function w(a,e,t,n,v,s,c){var r,o,i;return r=g(a),o=g(e),i=g(t),r.accessorProtocol||o.accessorProtocol||i.accessorProtocol?P(r.dtype)&&P(i.dtype)?(T(h(a,0),o,h(t,0),n,v,s,c),t):(R(r,o,i,n,v,s,c),t):(O(a,e,t,n,v,s,c),t)}C.exports=w
5
+ });var z=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),G=j(),B=D();z(G,"assign",B);module.exports=G;
6
+ /** @license Apache-2.0 */
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../lib/main.js", "../lib/assign.js", "../lib/index.js"],
4
+ "sourcesContent": ["/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 resolveGetter = require( '@stdlib/array-base-resolve-getter' );\n\n\n// MAIN //\n\n/**\n* Returns a new array by applying a mask to a provided input array and mapping the unmasked values according to a callback function.\n*\n* @param {Collection} x - input array\n* @param {Collection} mask - mask array\n* @param {Function} clbk - function to apply\n* @param {*} [thisArg] - function context\n* @returns {Array} output array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var y = mskrejectMap( x, mask, function( val ) {\n* return val * 2;\n* } );\n* // returns [ 2, 6 ]\n*/\nfunction mskrejectMap( x, mask, clbk, thisArg ) {\n\tvar xget;\n\tvar mget;\n\tvar out;\n\tvar i;\n\n\t// Resolve accessors for retrieving array elements:\n\txget = resolveGetter( x );\n\tmget = resolveGetter( mask );\n\n\t// Extract each desired element from the provided array...\n\tout = [];\n\tfor ( i = 0; i < x.length; i++ ) {\n\t\tif ( !mget( mask, i ) ) {\n\t\t\tout.push( clbk.call( thisArg, xget( x, i ), i, x ) ); // use `Array#push` to ensure \"fast\" elements\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mskrejectMap;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n* 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 isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );\nvar arraylike2object = require( '@stdlib/array-base-arraylike2object' );\nvar reinterpret = require( '@stdlib/strided-base-reinterpret-complex' );\n\n\n// FUNCTIONS //\n\n/**\n* Applies a mask to an indexed array, maps the unmasked values according to a callback function, and assigns to elements in an indexed output array.\n*\n* @private\n* @param {Collection} x - input array\n* @param {IntegerArray} mask - mask array\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array offset\n* @param {Function} clbk - function to apply\n* @param {*} [thisArg] - function context\n* @returns {Collection} output array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var out = [ 0, 0, 0, 0 ];\n*\n* var arr = indexed( x, mask, out, 1, 0, function( val ) {\n* return val * 2;\n* } );\n* // returns [ 2, 6, 0, 0 ]\n*/\nfunction indexed( x, mask, out, stride, offset, clbk, thisArg ) {\n\tvar io;\n\tvar i;\n\n\tio = offset;\n\tfor ( i = 0; i < x.length; i++ ) {\n\t\tif ( !mask[ i ] ) {\n\t\t\tout[ io ] = clbk.call(thisArg, x[ i ], i, x );\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n* Applies a mask to an accessor array, maps the unmasked values according to a callback function, and assigns to elements in an accessor output array.\n*\n* @private\n* @param {Object} x - input array object\n* @param {Object} mask - mask array object\n* @param {Object} out - output array object\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array offset\n* @param {Function} clbk - function to apply\n* @param {*} [thisArg] - function context\n* @returns {Collection} output array\n*\n* @example\n* var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = toAccessorArray( [ 1, 2, 3, 4 ] );\n* var mask = toAccessorArray( [ 0, 1, 0, 1 ] );\n*\n* var out = toAccessorArray( [ 0, 0, 0, 0 ] );\n* var arr = accessors( arraylike2object( x ), arraylike2object( mask ), arraylike2object( out ), 1, 0, function( val ) {\n* return val * 2;\n* } );\n*\n* var v = arr.get( 0 );\n* // returns 2\n*\n* v = arr.get( 1 );\n* // returns 6\n*/\nfunction accessors( x, mask, out, stride, offset, clbk, thisArg ) {\n\tvar xdata;\n\tvar mdata;\n\tvar odata;\n\tvar xget;\n\tvar mget;\n\tvar oset;\n\tvar io;\n\tvar i;\n\n\txdata = x.data;\n\tmdata = mask.data;\n\todata = out.data;\n\n\txget = x.accessors[ 0 ];\n\tmget = mask.accessors[ 0 ];\n\toset = out.accessors[ 1 ];\n\n\tio = offset;\n\tfor ( i = 0; i < xdata.length; i++ ) {\n\t\tif ( !mget( mdata, i ) ) {\n\t\t\toset( odata, io, clbk.call( thisArg, xget( xdata, i ), i, xdata ) );\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn odata;\n}\n\n/**\n* Applies a mask to a complex array, maps the unmasked values according to a callback function, and assigns to elements in a complex output array.\n*\n* @private\n* @param {Collection} x - real-valued floating-point input array view\n* @param {Object} mask - mask array object\n* @param {Collection} out - real-valued floating-point output array view\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array offset\n* @param {Function} clbk - function to apply\n* @param {*} [thisArg] - function context\n* @returns {Collection} output array view\n*\n* @example\n* var Float64Array = require( '@stdlib/array-float64' );\n* var arraylike2object = require( '@stdlib/array-base-arraylike2object' );\n*\n* var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var out = new Float64Array( 8 );\n*\n* var arr = complex( x, arraylike2object( mask ), out, 1, 0, function( val ) {\n* return val * 2;\n* } );\n* // returns <Float64Array>[ 2.0, 4.0, 10.0, 12.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction complex( x, mask, out, stride, offset, clbk, thisArg ) {\n\tvar mdata;\n\tvar mget;\n\tvar io;\n\tvar so;\n\tvar i;\n\tvar j;\n\n\tmdata = mask.data;\n\tmget = mask.accessors[ 0 ];\n\n\tso = stride * 2; // note: multiply by 2, as real-valued array consists of interleaved real and imaginary components\n\tio = offset * 2;\n\tfor ( i = 0; i < mdata.length; i++ ) {\n\t\tif ( !mget( mdata, i ) ) {\n\t\t\tj = i * 2;\n\t\t\tout[ io ] = clbk.call( thisArg, x[ j ], j, x );\n\t\t\tout[ io+1 ] = clbk.call( thisArg, x[ j+1 ], j+1, x );\n\t\t\tio += so;\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// MAIN //\n\n/**\n* Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array.\n*\n* @param {Collection} x - input array\n* @param {Collection} mask - mask array\n* @param {Collection} out - output array\n* @param {integer} stride - output array stride\n* @param {NonNegativeInteger} offset - output array offset\n* @param {Function} clbk - function to apply\n* @param {*} [thisArg] - function context\n* @returns {Collection} output array\n*\n* @example\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var out = [ 0, 0 ];\n* var arr = assign( x, mask, out, 1, 0, function( val ) {\n* return val * 2;\n* } );\n* // returns [ 2, 6 ]\n*\n* var bool = ( arr === out );\n* // returns true\n*/\nfunction assign( x, mask, out, stride, offset, clbk, thisArg ) {\n\tvar xo;\n\tvar mo;\n\tvar oo;\n\n\txo = arraylike2object( x );\n\tmo = arraylike2object( mask );\n\too = arraylike2object( out );\n\tif (\n\t\txo.accessorProtocol ||\n\t\tmo.accessorProtocol ||\n\t\too.accessorProtocol\n\t) {\n\t\t// Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland...\n\t\tif (\n\t\t\tisComplexDataType( xo.dtype ) &&\n\t\t\tisComplexDataType( oo.dtype )\n\t\t) {\n\t\t\tcomplex( reinterpret( x, 0 ), mo, reinterpret( out, 0 ), stride, offset, clbk, thisArg ); // eslint-disable-line max-len\n\t\t\treturn out;\n\t\t}\n\t\taccessors( xo, mo, oo, stride, offset, clbk, thisArg );\n\t\treturn out;\n\t}\n\tindexed( x, mask, out, stride, offset, clbk, thisArg );\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = assign;\n", "/**\n* @license Apache-2.0\n*\n* Copyright (c) 2024 The Stdlib Authors.\n*\n* Licensed under the Apache License, Version 2.0 (the \"License\");\n* you may not use this file except in compliance with the License.\n* You may obtain a copy of the License at\n*\n* http://www.apache.org/licenses/LICENSE-2.0\n*\n* Unless required by applicable law or agreed to in writing, software\n* distributed under the License is distributed on an \"AS IS\" BASIS,\n* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 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* Apply a mask to a provided input array and map the unmasked values according to a callback function.\n*\n* @module @stdlib/array-base-mskreject-map\n*\n* @example\n* var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );\n*\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var y = mskrejectMap( x, mask, function( val ) {\n* return val * 2;\n* } );\n* // returns [ 2, 6 ]\n*\n* @example\n* var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );\n*\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var out = [ 0, 0 ];\n* var arr = mskrejectMap.assign( x, mask, out, 1, 0, function( val ) {\n* return val + this;\n* }, 5 );\n* // returns [ 6, 8 ]\n*\n* var bool = ( arr === out );\n* // returns true\n*/\n\n// MODULES //\n\nvar setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );\nvar main = require( './main.js' );\nvar assign = require( './assign.js' );\n\n\n// MAIN //\n\nsetReadOnly( main, 'assign', assign );\n\n\n// EXPORTS //\n\nmodule.exports = main;\n"],
5
+ "mappings": "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",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "resolveGetter", "mskrejectMap", "x", "mask", "clbk", "thisArg", "xget", "mget", "out", "i", "require_assign", "__commonJSMin", "exports", "module", "isComplexDataType", "arraylike2object", "reinterpret", "indexed", "x", "mask", "out", "stride", "offset", "clbk", "thisArg", "io", "i", "accessors", "xdata", "mdata", "odata", "xget", "mget", "oset", "complex", "so", "j", "assign", "xo", "mo", "oo", "setReadOnly", "main", "assign"]
7
+ }
@@ -0,0 +1,152 @@
1
+ /*
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ // TypeScript Version: 4.1
20
+
21
+ /// <reference types="@stdlib/types"/>
22
+
23
+ import { Collection, AccessorArrayLike } from '@stdlib/types/array';
24
+
25
+ /**
26
+ * Returns a transformed element.
27
+ *
28
+ * @param value - current array element
29
+ * @returns transformed array element
30
+ */
31
+ type Unary<T, U, V> = ( this: U, value: T ) => V;
32
+
33
+ /**
34
+ * Returns a transformed element.
35
+ *
36
+ * @param value - current array element
37
+ * @param index - current array element index
38
+ * @returns transformed array element
39
+ */
40
+ type Binary<T, U, V> = ( this: U, value: T, index: number ) => V;
41
+
42
+ /**
43
+ * Returns a transformed element.
44
+ *
45
+ * @param value - current array element
46
+ * @param index - current array element index
47
+ * @param arr - input array
48
+ * @returns transformed array element
49
+ */
50
+ type Ternary<T, U, V> = ( this: U, value: T, index: number, arr: Collection<T> | AccessorArrayLike<T> ) => V;
51
+
52
+ /**
53
+ * Returns a transformed element.
54
+ *
55
+ * @param value - current array element
56
+ * @param index - current array element index
57
+ * @param arr - input array
58
+ * @returns transformed array element
59
+ */
60
+ type Callback<T, U, V> = Unary<T, U, V> | Binary<T, U, V> | Ternary<T, U, V>;
61
+
62
+ /**
63
+ * Interface describing `mskrejectMap`.
64
+ */
65
+ interface MskrejectMap {
66
+ /**
67
+ * Returns a new array by applying a mask and mapping the unmasked values according to a callback function.
68
+ *
69
+ * @param x - input array
70
+ * @param mask - mask array
71
+ * @param clbk - mapping function
72
+ * @param thisArg - function context
73
+ * @returns output array
74
+ *
75
+ * @example
76
+ * var x = [ 1, 2, 3, 4 ];
77
+ *
78
+ * var y = mskrejectMap( x, [ 0, 1, 0, 1 ], function( val ) {
79
+ * return val * 2;
80
+ * } );
81
+ * // returns [ 2, 6 ]
82
+ */
83
+ <T = unknown, U = unknown, V = unknown>( x: Collection<T> | AccessorArrayLike<T>, mask: Collection, clbk: Callback<T, U, V>, thisArg?: U ): Array<T>;
84
+
85
+ /**
86
+ * Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array.
87
+ *
88
+ * @param x - input array
89
+ * @param mask - mask array
90
+ * @param out - output array
91
+ * @param stride - output array stride
92
+ * @param offset - output array offset
93
+ * @param clbk - mapping function
94
+ * @param thisArg - function context
95
+ * @returns output array
96
+ *
97
+ * @example
98
+ * var x = [ 1, 2, 3, 4 ];
99
+ * var mask = [ 1, 0, 1, 0 ];
100
+ * var out = [ 0, 0, 0, 0 ];
101
+ *
102
+ * function clbk( val ) {
103
+ * return val * 2;
104
+ * }
105
+ *
106
+ * var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk );
107
+ * // returns [ 0, 8, 0, 4 ]
108
+ *
109
+ * var bool = ( arr === out );
110
+ * // returns true
111
+ */
112
+ assign<T = unknown, U = unknown, V = unknown>( x: Collection | AccessorArrayLike<T>, mask: Collection, out: Collection<T>, stride: number, offset: number, clbk: Callback<T, U, V>, thisArg?: U ): Collection<T>;
113
+ }
114
+
115
+ /**
116
+ * Returns a new array by applying a mask and mapping the unmasked values according to a callback function.
117
+ *
118
+ * @param x - input array
119
+ * @param mask - mask array
120
+ * @param clbk - mapping function
121
+ * @param thisArg - function context
122
+ * @returns output array
123
+ *
124
+ * @example
125
+ * var x = [ 1, 2, 3, 4 ];
126
+ *
127
+ * var y = mskrejectMap( x, [ 0, 1, 0, 1 ], function( val ) {
128
+ * return val * 2;
129
+ * } );
130
+ * // returns [ 2, 6 ]
131
+ *
132
+ * @example
133
+ * var x = [ 1, 2, 3, 4 ];
134
+ * var mask = [ 1, 0, 1, 0 ];
135
+ * var out = [ 0, 0, 0, 0 ];
136
+ *
137
+ * function clbk( val ) {
138
+ * return val * 2;
139
+ * }
140
+ *
141
+ * var arr = mskrejectMap.assign( x, mask, out, -2, out.length-1, clbk );
142
+ * // returns [ 0, 8, 0, 4 ]
143
+ *
144
+ * var bool = ( arr === out );
145
+ * // returns true
146
+ */
147
+ declare var mskrejectMap: MskrejectMap;
148
+
149
+
150
+ // EXPORTS //
151
+
152
+ export = mskrejectMap;
package/lib/assign.js ADDED
@@ -0,0 +1,237 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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 isComplexDataType = require( '@stdlib/array-base-assert-is-complex-floating-point-data-type' );
24
+ var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
25
+ var reinterpret = require( '@stdlib/strided-base-reinterpret-complex' );
26
+
27
+
28
+ // FUNCTIONS //
29
+
30
+ /**
31
+ * Applies a mask to an indexed array, maps the unmasked values according to a callback function, and assigns to elements in an indexed output array.
32
+ *
33
+ * @private
34
+ * @param {Collection} x - input array
35
+ * @param {IntegerArray} mask - mask array
36
+ * @param {Collection} out - output array
37
+ * @param {integer} stride - output array stride
38
+ * @param {NonNegativeInteger} offset - output array offset
39
+ * @param {Function} clbk - function to apply
40
+ * @param {*} [thisArg] - function context
41
+ * @returns {Collection} output array
42
+ *
43
+ * @example
44
+ * var x = [ 1, 2, 3, 4 ];
45
+ * var mask = [ 0, 1, 0, 1 ];
46
+ *
47
+ * var out = [ 0, 0, 0, 0 ];
48
+ *
49
+ * var arr = indexed( x, mask, out, 1, 0, function( val ) {
50
+ * return val * 2;
51
+ * } );
52
+ * // returns [ 2, 6, 0, 0 ]
53
+ */
54
+ function indexed( x, mask, out, stride, offset, clbk, thisArg ) {
55
+ var io;
56
+ var i;
57
+
58
+ io = offset;
59
+ for ( i = 0; i < x.length; i++ ) {
60
+ if ( !mask[ i ] ) {
61
+ out[ io ] = clbk.call(thisArg, x[ i ], i, x );
62
+ io += stride;
63
+ }
64
+ }
65
+ return out;
66
+ }
67
+
68
+ /**
69
+ * Applies a mask to an accessor array, maps the unmasked values according to a callback function, and assigns to elements in an accessor output array.
70
+ *
71
+ * @private
72
+ * @param {Object} x - input array object
73
+ * @param {Object} mask - mask array object
74
+ * @param {Object} out - output array object
75
+ * @param {integer} stride - output array stride
76
+ * @param {NonNegativeInteger} offset - output array offset
77
+ * @param {Function} clbk - function to apply
78
+ * @param {*} [thisArg] - function context
79
+ * @returns {Collection} output array
80
+ *
81
+ * @example
82
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
83
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
84
+ *
85
+ * var x = toAccessorArray( [ 1, 2, 3, 4 ] );
86
+ * var mask = toAccessorArray( [ 0, 1, 0, 1 ] );
87
+ *
88
+ * var out = toAccessorArray( [ 0, 0, 0, 0 ] );
89
+ * var arr = accessors( arraylike2object( x ), arraylike2object( mask ), arraylike2object( out ), 1, 0, function( val ) {
90
+ * return val * 2;
91
+ * } );
92
+ *
93
+ * var v = arr.get( 0 );
94
+ * // returns 2
95
+ *
96
+ * v = arr.get( 1 );
97
+ * // returns 6
98
+ */
99
+ function accessors( x, mask, out, stride, offset, clbk, thisArg ) {
100
+ var xdata;
101
+ var mdata;
102
+ var odata;
103
+ var xget;
104
+ var mget;
105
+ var oset;
106
+ var io;
107
+ var i;
108
+
109
+ xdata = x.data;
110
+ mdata = mask.data;
111
+ odata = out.data;
112
+
113
+ xget = x.accessors[ 0 ];
114
+ mget = mask.accessors[ 0 ];
115
+ oset = out.accessors[ 1 ];
116
+
117
+ io = offset;
118
+ for ( i = 0; i < xdata.length; i++ ) {
119
+ if ( !mget( mdata, i ) ) {
120
+ oset( odata, io, clbk.call( thisArg, xget( xdata, i ), i, xdata ) );
121
+ io += stride;
122
+ }
123
+ }
124
+ return odata;
125
+ }
126
+
127
+ /**
128
+ * Applies a mask to a complex array, maps the unmasked values according to a callback function, and assigns to elements in a complex output array.
129
+ *
130
+ * @private
131
+ * @param {Collection} x - real-valued floating-point input array view
132
+ * @param {Object} mask - mask array object
133
+ * @param {Collection} out - real-valued floating-point output array view
134
+ * @param {integer} stride - output array stride
135
+ * @param {NonNegativeInteger} offset - output array offset
136
+ * @param {Function} clbk - function to apply
137
+ * @param {*} [thisArg] - function context
138
+ * @returns {Collection} output array view
139
+ *
140
+ * @example
141
+ * var Float64Array = require( '@stdlib/array-float64' );
142
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
143
+ *
144
+ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
145
+ * var mask = [ 0, 1, 0, 1 ];
146
+ *
147
+ * var out = new Float64Array( 8 );
148
+ *
149
+ * var arr = complex( x, arraylike2object( mask ), out, 1, 0, function( val ) {
150
+ * return val * 2;
151
+ * } );
152
+ * // returns <Float64Array>[ 2.0, 4.0, 10.0, 12.0, 0.0, 0.0, 0.0, 0.0 ]
153
+ */
154
+ function complex( x, mask, out, stride, offset, clbk, thisArg ) {
155
+ var mdata;
156
+ var mget;
157
+ var io;
158
+ var so;
159
+ var i;
160
+ var j;
161
+
162
+ mdata = mask.data;
163
+ mget = mask.accessors[ 0 ];
164
+
165
+ so = stride * 2; // note: multiply by 2, as real-valued array consists of interleaved real and imaginary components
166
+ io = offset * 2;
167
+ for ( i = 0; i < mdata.length; i++ ) {
168
+ if ( !mget( mdata, i ) ) {
169
+ j = i * 2;
170
+ out[ io ] = clbk.call( thisArg, x[ j ], j, x );
171
+ out[ io+1 ] = clbk.call( thisArg, x[ j+1 ], j+1, x );
172
+ io += so;
173
+ }
174
+ }
175
+ return out;
176
+ }
177
+
178
+
179
+ // MAIN //
180
+
181
+ /**
182
+ * Applies a mask to a provided input array, maps the unmasked values according to a callback function, and assigns to elements in a provided output array.
183
+ *
184
+ * @param {Collection} x - input array
185
+ * @param {Collection} mask - mask array
186
+ * @param {Collection} out - output array
187
+ * @param {integer} stride - output array stride
188
+ * @param {NonNegativeInteger} offset - output array offset
189
+ * @param {Function} clbk - function to apply
190
+ * @param {*} [thisArg] - function context
191
+ * @returns {Collection} output array
192
+ *
193
+ * @example
194
+ * var x = [ 1, 2, 3, 4 ];
195
+ * var mask = [ 0, 1, 0, 1 ];
196
+ *
197
+ * var out = [ 0, 0 ];
198
+ * var arr = assign( x, mask, out, 1, 0, function( val ) {
199
+ * return val * 2;
200
+ * } );
201
+ * // returns [ 2, 6 ]
202
+ *
203
+ * var bool = ( arr === out );
204
+ * // returns true
205
+ */
206
+ function assign( x, mask, out, stride, offset, clbk, thisArg ) {
207
+ var xo;
208
+ var mo;
209
+ var oo;
210
+
211
+ xo = arraylike2object( x );
212
+ mo = arraylike2object( mask );
213
+ oo = arraylike2object( out );
214
+ if (
215
+ xo.accessorProtocol ||
216
+ mo.accessorProtocol ||
217
+ oo.accessorProtocol
218
+ ) {
219
+ // Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland...
220
+ if (
221
+ isComplexDataType( xo.dtype ) &&
222
+ isComplexDataType( oo.dtype )
223
+ ) {
224
+ complex( reinterpret( x, 0 ), mo, reinterpret( out, 0 ), stride, offset, clbk, thisArg ); // eslint-disable-line max-len
225
+ return out;
226
+ }
227
+ accessors( xo, mo, oo, stride, offset, clbk, thisArg );
228
+ return out;
229
+ }
230
+ indexed( x, mask, out, stride, offset, clbk, thisArg );
231
+ return out;
232
+ }
233
+
234
+
235
+ // EXPORTS //
236
+
237
+ module.exports = assign;
package/lib/index.js ADDED
@@ -0,0 +1,67 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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
+ /**
22
+ * Apply a mask to a provided input array and map the unmasked values according to a callback function.
23
+ *
24
+ * @module @stdlib/array-base-mskreject-map
25
+ *
26
+ * @example
27
+ * var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );
28
+ *
29
+ * var x = [ 1, 2, 3, 4 ];
30
+ * var mask = [ 0, 1, 0, 1 ];
31
+ *
32
+ * var y = mskrejectMap( x, mask, function( val ) {
33
+ * return val * 2;
34
+ * } );
35
+ * // returns [ 2, 6 ]
36
+ *
37
+ * @example
38
+ * var mskrejectMap = require( '@stdlib/array-base-mskreject-map' );
39
+ *
40
+ * var x = [ 1, 2, 3, 4 ];
41
+ * var mask = [ 0, 1, 0, 1 ];
42
+ *
43
+ * var out = [ 0, 0 ];
44
+ * var arr = mskrejectMap.assign( x, mask, out, 1, 0, function( val ) {
45
+ * return val + this;
46
+ * }, 5 );
47
+ * // returns [ 6, 8 ]
48
+ *
49
+ * var bool = ( arr === out );
50
+ * // returns true
51
+ */
52
+
53
+ // MODULES //
54
+
55
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
56
+ var main = require( './main.js' );
57
+ var assign = require( './assign.js' );
58
+
59
+
60
+ // MAIN //
61
+
62
+ setReadOnly( main, 'assign', assign );
63
+
64
+
65
+ // EXPORTS //
66
+
67
+ module.exports = main;
package/lib/main.js ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2024 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 resolveGetter = require( '@stdlib/array-base-resolve-getter' );
24
+
25
+
26
+ // MAIN //
27
+
28
+ /**
29
+ * Returns a new array by applying a mask to a provided input array and mapping the unmasked values according to a callback function.
30
+ *
31
+ * @param {Collection} x - input array
32
+ * @param {Collection} mask - mask array
33
+ * @param {Function} clbk - function to apply
34
+ * @param {*} [thisArg] - function context
35
+ * @returns {Array} output array
36
+ *
37
+ * @example
38
+ * var x = [ 1, 2, 3, 4 ];
39
+ * var mask = [ 0, 1, 0, 1 ];
40
+ *
41
+ * var y = mskrejectMap( x, mask, function( val ) {
42
+ * return val * 2;
43
+ * } );
44
+ * // returns [ 2, 6 ]
45
+ */
46
+ function mskrejectMap( x, mask, clbk, thisArg ) {
47
+ var xget;
48
+ var mget;
49
+ var out;
50
+ var i;
51
+
52
+ // Resolve accessors for retrieving array elements:
53
+ xget = resolveGetter( x );
54
+ mget = resolveGetter( mask );
55
+
56
+ // Extract each desired element from the provided array...
57
+ out = [];
58
+ for ( i = 0; i < x.length; i++ ) {
59
+ if ( !mget( mask, i ) ) {
60
+ out.push( clbk.call( thisArg, xget( x, i ), i, x ) ); // use `Array#push` to ensure "fast" elements
61
+ }
62
+ }
63
+ return out;
64
+ }
65
+
66
+
67
+ // EXPORTS //
68
+
69
+ module.exports = mskrejectMap;
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@stdlib/array-base-mskreject-map",
3
+ "version": "0.0.1",
4
+ "description": "Apply a mask to a provided input array and map the unmasked values according to a callback function.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "doc": "./docs",
19
+ "lib": "./lib",
20
+ "dist": "./dist"
21
+ },
22
+ "types": "./docs/types",
23
+ "scripts": {},
24
+ "homepage": "https://stdlib.io",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git://github.com/stdlib-js/array-base-mskreject-map.git"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/stdlib-js/stdlib/issues"
31
+ },
32
+ "dependencies": {
33
+ "@stdlib/array-base-arraylike2object": "^0.2.1",
34
+ "@stdlib/array-base-assert-is-complex-floating-point-data-type": "^0.2.1",
35
+ "@stdlib/array-base-resolve-getter": "^0.2.1",
36
+ "@stdlib/strided-base-reinterpret-complex": "^0.1.1",
37
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1"
38
+ },
39
+ "devDependencies": {},
40
+ "engines": {
41
+ "node": ">=0.10.0",
42
+ "npm": ">2.7.0"
43
+ },
44
+ "os": [
45
+ "aix",
46
+ "darwin",
47
+ "freebsd",
48
+ "linux",
49
+ "macos",
50
+ "openbsd",
51
+ "sunos",
52
+ "win32",
53
+ "windows"
54
+ ],
55
+ "keywords": [
56
+ "stdlib",
57
+ "utilities",
58
+ "utils",
59
+ "generic",
60
+ "array",
61
+ "take",
62
+ "extract",
63
+ "copy",
64
+ "index",
65
+ "mask",
66
+ "reject",
67
+ "filter"
68
+ ],
69
+ "funding": {
70
+ "type": "opencollective",
71
+ "url": "https://opencollective.com/stdlib"
72
+ }
73
+ }