@stdlib/array-base-mskreject 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/README.md CHANGED
@@ -33,7 +33,7 @@ limitations under the License.
33
33
 
34
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
35
 
36
- > Return a new array by applying a mask to a provided input array.
36
+ > Apply a mask to a provided input array.
37
37
 
38
38
  <section class="installation">
39
39
 
@@ -64,6 +64,38 @@ var y = mskreject( x, [ 0, 1, 0, 1 ] );
64
64
  // returns [ 1, 3 ]
65
65
  ```
66
66
 
67
+ The function supports the following parameters:
68
+
69
+ - **x**: input array.
70
+ - **mask**: mask array.
71
+
72
+ The function **always** returns a new "generic" array.
73
+
74
+ #### mskreject.assign( x, mask, out, stride, offset )
75
+
76
+ Applies a mask to a provided input array and assigns unmasked values to elements in a provided output array.
77
+
78
+ ```javascript
79
+ var x = [ 1, 2, 3, 4 ];
80
+ var mask = [ 1, 0, 1, 0 ];
81
+
82
+ var out = [ 0, 0, 0, 0 ];
83
+
84
+ var arr = mskreject.assign( x, mask, out, -2, out.length-1 );
85
+ // returns [ 0, 4, 0, 2 ]
86
+
87
+ var bool = ( arr === out );
88
+ // returns true
89
+ ```
90
+
91
+ The function supports the following parameters:
92
+
93
+ - **x**: input array.
94
+ - **mask**: mask array.
95
+ - **out**: output array.
96
+ - **stride**: output array stride.
97
+ - **offset**: output array offset.
98
+
67
99
  </section>
68
100
 
69
101
  <!-- /.usage -->
@@ -72,7 +104,6 @@ var y = mskreject( x, [ 0, 1, 0, 1 ] );
72
104
 
73
105
  ## Notes
74
106
 
75
- - The function **always** returns a new "generic" array.
76
107
  - If a `mask` array element is falsy, the corresponding element in `x` is **included** in the output array; otherwise, the corresponding element in `x` is "masked" and thus **excluded** from the output array.
77
108
 
78
109
  </section>
@@ -92,17 +123,16 @@ var mskreject = require( '@stdlib/array-base-mskreject' );
92
123
 
93
124
  // Generate a linearly spaced array:
94
125
  var x = zeroTo( 20 );
126
+ console.log( x );
95
127
 
96
128
  // Generate a random mask:
97
129
  var mask = bernoulli( x.length, 0.5, {
98
130
  'dtype': 'generic'
99
131
  });
132
+ console.log( mask );
100
133
 
101
134
  // Filter an array using the mask:
102
135
  var y = mskreject( x, mask );
103
-
104
- console.log( x );
105
- console.log( mask );
106
136
  console.log( y );
107
137
  ```
108
138
 
@@ -157,8 +187,8 @@ Copyright &copy; 2016-2024. The Stdlib [Authors][stdlib-authors].
157
187
  [npm-image]: http://img.shields.io/npm/v/@stdlib/array-base-mskreject.svg
158
188
  [npm-url]: https://npmjs.org/package/@stdlib/array-base-mskreject
159
189
 
160
- [test-image]: https://github.com/stdlib-js/array-base-mskreject/actions/workflows/test.yml/badge.svg?branch=v0.1.0
161
- [test-url]: https://github.com/stdlib-js/array-base-mskreject/actions/workflows/test.yml?query=branch:v0.1.0
190
+ [test-image]: https://github.com/stdlib-js/array-base-mskreject/actions/workflows/test.yml/badge.svg?branch=v0.2.1
191
+ [test-url]: https://github.com/stdlib-js/array-base-mskreject/actions/workflows/test.yml?query=branch:v0.2.1
162
192
 
163
193
  [coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/array-base-mskreject/main.svg
164
194
  [coverage-url]: https://codecov.io/github/stdlib-js/array-base-mskreject?branch=main
package/dist/index.js CHANGED
@@ -1,5 +1,7 @@
1
- "use strict";var n=function(e,r){return function(){return r||e((r={exports:{}}).exports,r),r.exports}};var o=n(function(p,a){
2
- var v=require('@stdlib/array-base-resolve-getter/dist');function c(e,r){var s,u,i,t;for(s=v(e),u=v(r),i=[],t=0;t<e.length;t++)u(r,t)||i.push(s(e,t));return i}a.exports=c
3
- });var f=o();module.exports=f;
1
+ "use strict";var f=function(a,t){return function(){return t||a((t={exports:{}}).exports,t),t.exports}};var m=f(function(z,q){
2
+ var p=require('@stdlib/array-base-resolve-getter/dist');function b(a,t){var e,v,i,r;for(e=p(a),v=p(t),i=[],r=0;r<a.length;r++)v(t,r)||i.push(e(a,r));return i}q.exports=b
3
+ });var x=f(function(A,j){
4
+ var h=require('@stdlib/array-base-assert-is-complex-floating-point-data-type/dist'),d=require('@stdlib/array-base-arraylike2object/dist'),y=require('@stdlib/strided-base-reinterpret-complex/dist');function C(a,t,e,v,i){var r,s;for(r=i,s=0;s<a.length;s++)t[s]||(e[r]=a[s],r+=v);return e}function D(a,t,e,v,i){var r,s,o,u,c,n,l,g;for(r=a.data,s=t.data,o=e.data,u=a.accessors[0],c=t.accessors[0],n=e.accessors[1],l=i,g=0;g<r.length;g++)c(s,g)||(n(o,l,u(r,g)),l+=v);return o}function G(a,t,e,v,i){var r,s,o,u,c,n;for(r=t.data,s=t.accessors[0],u=v*2,o=i*2,c=0;c<r.length;c++)s(r,c)||(n=c*2,e[o]=a[n],e[o+1]=a[n+1],o+=u);return e}function O(a,t,e,v,i){var r,s,o;return r=d(a),s=d(t),o=d(e),r.accessorProtocol||s.accessorProtocol||o.accessorProtocol?h(r.dtype)&&h(o.dtype)?(G(y(a,0),s,y(e,0),v,i),e):(D(r,s,o,v,i),e):(C(a,t,e,v,i),e)}j.exports=O
5
+ });var R=require('@stdlib/utils-define-nonenumerable-read-only-property/dist'),P=m(),T=x();R(P,"assign",T);module.exports=P;
4
6
  /** @license Apache-2.0 */
5
7
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../lib/main.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.\n*\n* @param {Collection} x - input array\n* @param {Collection} mask - mask array\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 = mskreject( x, mask );\n* // returns [ 1, 3 ]\n*/\nfunction mskreject( x, mask ) {\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( xget( x, i ) ); // use `Array#push` to ensure \"fast\" elements\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mskreject;\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* Return a new array by applying a mask to a provided input array.\n*\n* @module @stdlib/array-base-mskreject\n*\n* @example\n* var mskreject = require( '@stdlib/array-base-mskreject' );\n*\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var y = mskreject( x, mask );\n* // returns [ 1, 3 ]\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,EAAgB,QAAS,mCAAoC,EAmBjE,SAASC,EAAWC,EAAGC,EAAO,CAC7B,IAAIC,EACAC,EACAC,EACAC,EAQJ,IALAH,EAAOJ,EAAeE,CAAE,EACxBG,EAAOL,EAAeG,CAAK,EAG3BG,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIL,EAAE,OAAQK,IACpBF,EAAMF,EAAMI,CAAE,GACnBD,EAAI,KAAMF,EAAMF,EAAGK,CAAE,CAAE,EAGzB,OAAOD,CACR,CAKAP,EAAO,QAAUE,IC3BjB,IAAIO,EAAO,IAKX,OAAO,QAAUA",
6
- "names": ["require_main", "__commonJSMin", "exports", "module", "resolveGetter", "mskreject", "x", "mask", "xget", "mget", "out", "i", "main"]
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.\n*\n* @param {Collection} x - input array\n* @param {Collection} mask - mask array\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 = mskreject( x, mask );\n* // returns [ 1, 3 ]\n*/\nfunction mskreject( x, mask ) {\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( xget( x, i ) ); // use `Array#push` to ensure \"fast\" elements\n\t\t}\n\t}\n\treturn out;\n}\n\n\n// EXPORTS //\n\nmodule.exports = mskreject;\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 and assigns unmasked values 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* @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 );\n* // returns [ 1, 3, 0, 0 ]\n*/\nfunction indexed( x, mask, out, stride, offset ) {\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 ] = x[ i ];\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n* Applies a mask to an accessor array and assigns unmasked values 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* @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 );\n*\n* var v = arr.get( 0 );\n* // returns 1\n*\n* v = arr.get( 1 );\n* // returns 3\n*/\nfunction accessors( x, mask, out, stride, offset ) {\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, xget( xdata, i ) );\n\t\t\tio += stride;\n\t\t}\n\t}\n\treturn odata;\n}\n\n/**\n* Applies a mask to a complex array and assigns unmasked values 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* @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 );\n* // returns <Float64Array>[ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ]\n*/\nfunction complex( x, mask, out, stride, offset ) {\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 ] = x[ j ];\n\t\t\tout[ io+1 ] = x[ j+1 ];\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 and assigns unmasked values 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* @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 );\n* // returns [ 1, 3 ]\n*\n* var bool = ( arr === out );\n* // returns true\n*/\nfunction assign( x, mask, out, stride, offset ) {\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 ); // eslint-disable-line max-len\n\t\t\treturn out;\n\t\t}\n\t\taccessors( xo, mo, oo, stride, offset );\n\t\treturn out;\n\t}\n\tindexed( x, mask, out, stride, offset );\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.\n*\n* @module @stdlib/array-base-mskreject\n*\n* @example\n* var mskreject = require( '@stdlib/array-base-mskreject' );\n*\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var y = mskreject( x, mask );\n* // returns [ 1, 3 ]\n*\n* @example\n* var mskreject = require( '@stdlib/array-base-mskreject' );\n*\n* var x = [ 1, 2, 3, 4 ];\n* var mask = [ 0, 1, 0, 1 ];\n*\n* var out = [ 0, 0 ];\n* var arr = mskreject.assign( x, mask, out, 1, 0 );\n* // returns [ 1, 3 ]\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": "uGAAA,IAAAA,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAgB,QAAS,mCAAoC,EAmBjE,SAASC,EAAWC,EAAGC,EAAO,CAC7B,IAAIC,EACAC,EACAC,EACAC,EAQJ,IALAH,EAAOJ,EAAeE,CAAE,EACxBG,EAAOL,EAAeG,CAAK,EAG3BG,EAAM,CAAC,EACDC,EAAI,EAAGA,EAAIL,EAAE,OAAQK,IACpBF,EAAMF,EAAMI,CAAE,GACnBD,EAAI,KAAMF,EAAMF,EAAGK,CAAE,CAAE,EAGzB,OAAOD,CACR,CAKAP,EAAO,QAAUE,IChEjB,IAAAO,EAAAC,EAAA,SAAAC,EAAAC,EAAA,cAsBA,IAAIC,EAAoB,QAAS,+DAAgE,EAC7FC,EAAmB,QAAS,qCAAsC,EAClEC,EAAc,QAAS,0CAA2C,EAyBtE,SAASC,EAASC,EAAGC,EAAMC,EAAKC,EAAQC,EAAS,CAChD,IAAIC,EACAC,EAGJ,IADAD,EAAKD,EACCE,EAAI,EAAGA,EAAIN,EAAE,OAAQM,IACpBL,EAAMK,CAAE,IACbJ,EAAKG,CAAG,EAAIL,EAAGM,CAAE,EACjBD,GAAMF,GAGR,OAAOD,CACR,CA6BA,SAASK,EAAWP,EAAGC,EAAMC,EAAKC,EAAQC,EAAS,CAClD,IAAII,EACAC,EACAC,EACAC,EACAC,EACAC,EACAR,EACAC,EAWJ,IATAE,EAAQR,EAAE,KACVS,EAAQR,EAAK,KACbS,EAAQR,EAAI,KAEZS,EAAOX,EAAE,UAAW,CAAE,EACtBY,EAAOX,EAAK,UAAW,CAAE,EACzBY,EAAOX,EAAI,UAAW,CAAE,EAExBG,EAAKD,EACCE,EAAI,EAAGA,EAAIE,EAAM,OAAQF,IACxBM,EAAMH,EAAOH,CAAE,IACpBO,EAAMH,EAAOL,EAAIM,EAAMH,EAAOF,CAAE,CAAE,EAClCD,GAAMF,GAGR,OAAOO,CACR,CAyBA,SAASI,EAASd,EAAGC,EAAMC,EAAKC,EAAQC,EAAS,CAChD,IAAIK,EACAG,EACAP,EACAU,EACAT,EACAU,EAOJ,IALAP,EAAQR,EAAK,KACbW,EAAOX,EAAK,UAAW,CAAE,EAEzBc,EAAKZ,EAAS,EACdE,EAAKD,EAAS,EACRE,EAAI,EAAGA,EAAIG,EAAM,OAAQH,IACxBM,EAAMH,EAAOH,CAAE,IACpBU,EAAIV,EAAI,EACRJ,EAAKG,CAAG,EAAIL,EAAGgB,CAAE,EACjBd,EAAKG,EAAG,CAAE,EAAIL,EAAGgB,EAAE,CAAE,EACrBX,GAAMU,GAGR,OAAOb,CACR,CA0BA,SAASe,EAAQjB,EAAGC,EAAMC,EAAKC,EAAQC,EAAS,CAC/C,IAAIc,EACAC,EACAC,EAKJ,OAHAF,EAAKrB,EAAkBG,CAAE,EACzBmB,EAAKtB,EAAkBI,CAAK,EAC5BmB,EAAKvB,EAAkBK,CAAI,EAE1BgB,EAAG,kBACHC,EAAG,kBACHC,EAAG,iBAIFxB,EAAmBsB,EAAG,KAAM,GAC5BtB,EAAmBwB,EAAG,KAAM,GAE5BN,EAAShB,EAAaE,EAAG,CAAE,EAAGmB,EAAIrB,EAAaI,EAAK,CAAE,EAAGC,EAAQC,CAAO,EACjEF,IAERK,EAAWW,EAAIC,EAAIC,EAAIjB,EAAQC,CAAO,EAC/BF,IAERH,EAASC,EAAGC,EAAMC,EAAKC,EAAQC,CAAO,EAC/BF,EACR,CAKAP,EAAO,QAAUsB,IC1KjB,IAAII,EAAc,QAAS,uDAAwD,EAC/EC,EAAO,IACPC,EAAS,IAKbF,EAAaC,EAAM,SAAUC,CAAO,EAKpC,OAAO,QAAUD",
6
+ "names": ["require_main", "__commonJSMin", "exports", "module", "resolveGetter", "mskreject", "x", "mask", "xget", "mget", "out", "i", "require_assign", "__commonJSMin", "exports", "module", "isComplexDataType", "arraylike2object", "reinterpret", "indexed", "x", "mask", "out", "stride", "offset", "io", "i", "accessors", "xdata", "mdata", "odata", "xget", "mget", "oset", "complex", "so", "j", "assign", "xo", "mo", "oo", "setReadOnly", "main", "assign"]
7
7
  }
package/lib/assign.js ADDED
@@ -0,0 +1,221 @@
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 and assigns unmasked values 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
+ * @returns {Collection} output array
40
+ *
41
+ * @example
42
+ * var x = [ 1, 2, 3, 4 ];
43
+ * var mask = [ 0, 1, 0, 1 ];
44
+ *
45
+ * var out = [ 0, 0, 0, 0 ];
46
+ *
47
+ * var arr = indexed( x, mask, out, 1, 0 );
48
+ * // returns [ 1, 3, 0, 0 ]
49
+ */
50
+ function indexed( x, mask, out, stride, offset ) {
51
+ var io;
52
+ var i;
53
+
54
+ io = offset;
55
+ for ( i = 0; i < x.length; i++ ) {
56
+ if ( !mask[ i ] ) {
57
+ out[ io ] = x[ i ];
58
+ io += stride;
59
+ }
60
+ }
61
+ return out;
62
+ }
63
+
64
+ /**
65
+ * Applies a mask to an accessor array and assigns unmasked values to elements in an accessor output array.
66
+ *
67
+ * @private
68
+ * @param {Object} x - input array object
69
+ * @param {Object} mask - mask array object
70
+ * @param {Object} out - output array object
71
+ * @param {integer} stride - output array stride
72
+ * @param {NonNegativeInteger} offset - output array offset
73
+ * @returns {Collection} output array
74
+ *
75
+ * @example
76
+ * var toAccessorArray = require( '@stdlib/array-base-to-accessor-array' );
77
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
78
+ *
79
+ * var x = toAccessorArray( [ 1, 2, 3, 4 ] );
80
+ * var mask = toAccessorArray( [ 0, 1, 0, 1 ] );
81
+ *
82
+ * var out = toAccessorArray( [ 0, 0, 0, 0 ] );
83
+ * var arr = accessors( arraylike2object( x ), arraylike2object( mask ), arraylike2object( out ), 1, 0 );
84
+ *
85
+ * var v = arr.get( 0 );
86
+ * // returns 1
87
+ *
88
+ * v = arr.get( 1 );
89
+ * // returns 3
90
+ */
91
+ function accessors( x, mask, out, stride, offset ) {
92
+ var xdata;
93
+ var mdata;
94
+ var odata;
95
+ var xget;
96
+ var mget;
97
+ var oset;
98
+ var io;
99
+ var i;
100
+
101
+ xdata = x.data;
102
+ mdata = mask.data;
103
+ odata = out.data;
104
+
105
+ xget = x.accessors[ 0 ];
106
+ mget = mask.accessors[ 0 ];
107
+ oset = out.accessors[ 1 ];
108
+
109
+ io = offset;
110
+ for ( i = 0; i < xdata.length; i++ ) {
111
+ if ( !mget( mdata, i ) ) {
112
+ oset( odata, io, xget( xdata, i ) );
113
+ io += stride;
114
+ }
115
+ }
116
+ return odata;
117
+ }
118
+
119
+ /**
120
+ * Applies a mask to a complex array and assigns unmasked values to elements in a complex output array.
121
+ *
122
+ * @private
123
+ * @param {Collection} x - real-valued floating-point input array view
124
+ * @param {Object} mask - mask array object
125
+ * @param {Collection} out - real-valued floating-point output array view
126
+ * @param {integer} stride - output array stride
127
+ * @param {NonNegativeInteger} offset - output array offset
128
+ * @returns {Collection} output array view
129
+ *
130
+ * @example
131
+ * var Float64Array = require( '@stdlib/array-float64' );
132
+ * var arraylike2object = require( '@stdlib/array-base-arraylike2object' );
133
+ *
134
+ * var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
135
+ * var mask = [ 0, 1, 0, 1 ];
136
+ *
137
+ * var out = new Float64Array( 8 );
138
+ *
139
+ * var arr = complex( x, arraylike2object( mask ), out, 1, 0 );
140
+ * // returns <Float64Array>[ 1.0, 2.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0 ]
141
+ */
142
+ function complex( x, mask, out, stride, offset ) {
143
+ var mdata;
144
+ var mget;
145
+ var io;
146
+ var so;
147
+ var i;
148
+ var j;
149
+
150
+ mdata = mask.data;
151
+ mget = mask.accessors[ 0 ];
152
+
153
+ so = stride * 2; // note: multiply by 2, as real-valued array consists of interleaved real and imaginary components
154
+ io = offset * 2;
155
+ for ( i = 0; i < mdata.length; i++ ) {
156
+ if ( !mget( mdata, i ) ) {
157
+ j = i * 2;
158
+ out[ io ] = x[ j ];
159
+ out[ io+1 ] = x[ j+1 ];
160
+ io += so;
161
+ }
162
+ }
163
+ return out;
164
+ }
165
+
166
+
167
+ // MAIN //
168
+
169
+ /**
170
+ * Applies a mask to a provided input array and assigns unmasked values to elements in a provided output array.
171
+ *
172
+ * @param {Collection} x - input array
173
+ * @param {Collection} mask - mask array
174
+ * @param {Collection} out - output array
175
+ * @param {integer} stride - output array stride
176
+ * @param {NonNegativeInteger} offset - output array offset
177
+ * @returns {Collection} output array
178
+ *
179
+ * @example
180
+ * var x = [ 1, 2, 3, 4 ];
181
+ * var mask = [ 0, 1, 0, 1 ];
182
+ *
183
+ * var out = [ 0, 0 ];
184
+ * var arr = assign( x, mask, out, 1, 0 );
185
+ * // returns [ 1, 3 ]
186
+ *
187
+ * var bool = ( arr === out );
188
+ * // returns true
189
+ */
190
+ function assign( x, mask, out, stride, offset ) {
191
+ var xo;
192
+ var mo;
193
+ var oo;
194
+
195
+ xo = arraylike2object( x );
196
+ mo = arraylike2object( mask );
197
+ oo = arraylike2object( out );
198
+ if (
199
+ xo.accessorProtocol ||
200
+ mo.accessorProtocol ||
201
+ oo.accessorProtocol
202
+ ) {
203
+ // Note: we only explicitly support complex-to-complex, as this function should not be concerned with casting rules, etc. That is left to userland...
204
+ if (
205
+ isComplexDataType( xo.dtype ) &&
206
+ isComplexDataType( oo.dtype )
207
+ ) {
208
+ complex( reinterpret( x, 0 ), mo, reinterpret( out, 0 ), stride, offset ); // eslint-disable-line max-len
209
+ return out;
210
+ }
211
+ accessors( xo, mo, oo, stride, offset );
212
+ return out;
213
+ }
214
+ indexed( x, mask, out, stride, offset );
215
+ return out;
216
+ }
217
+
218
+
219
+ // EXPORTS //
220
+
221
+ module.exports = assign;
package/lib/index.js CHANGED
@@ -19,7 +19,7 @@
19
19
  'use strict';
20
20
 
21
21
  /**
22
- * Return a new array by applying a mask to a provided input array.
22
+ * Apply a mask to a provided input array.
23
23
  *
24
24
  * @module @stdlib/array-base-mskreject
25
25
  *
@@ -31,11 +31,31 @@
31
31
  *
32
32
  * var y = mskreject( x, mask );
33
33
  * // returns [ 1, 3 ]
34
+ *
35
+ * @example
36
+ * var mskreject = require( '@stdlib/array-base-mskreject' );
37
+ *
38
+ * var x = [ 1, 2, 3, 4 ];
39
+ * var mask = [ 0, 1, 0, 1 ];
40
+ *
41
+ * var out = [ 0, 0 ];
42
+ * var arr = mskreject.assign( x, mask, out, 1, 0 );
43
+ * // returns [ 1, 3 ]
44
+ *
45
+ * var bool = ( arr === out );
46
+ * // returns true
34
47
  */
35
48
 
36
49
  // MODULES //
37
50
 
51
+ var setReadOnly = require( '@stdlib/utils-define-nonenumerable-read-only-property' );
38
52
  var main = require( './main.js' );
53
+ var assign = require( './assign.js' );
54
+
55
+
56
+ // MAIN //
57
+
58
+ setReadOnly( main, 'assign', assign );
39
59
 
40
60
 
41
61
  // EXPORTS //
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stdlib/array-base-mskreject",
3
- "version": "0.1.0",
4
- "description": "Return a new array by applying a mask to a provided input array.",
3
+ "version": "0.2.1",
4
+ "description": "Apply a mask to a provided input array.",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
7
7
  "name": "The Stdlib Authors",
@@ -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,23 +30,13 @@
37
30
  "url": "https://github.com/stdlib-js/stdlib/issues"
38
31
  },
39
32
  "dependencies": {
40
- "@stdlib/array-base-resolve-getter": "^0.1.0",
41
- "@stdlib/types": "^0.2.0"
42
- },
43
- "devDependencies": {
44
- "@stdlib/array-base-zero-to": "^0.1.0",
45
- "@stdlib/array-base-zeros": "^0.1.1",
46
- "@stdlib/array-complex64": "^0.1.0",
47
- "@stdlib/assert-is-array": "^0.1.1",
48
- "@stdlib/assert-is-same-complex64": "^0.1.0",
49
- "@stdlib/math-base-special-pow": "^0.1.0",
50
- "@stdlib/random-array-bernoulli": "^0.1.0",
51
- "tape": "git+https://github.com/kgryte/tape.git#fix/globby",
52
- "istanbul": "^0.4.1",
53
- "tap-min": "git+https://github.com/Planeshifter/tap-min.git",
54
- "@stdlib/bench-harness": "^0.1.2",
55
- "@stdlib/bench": "^0.2.1"
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.0",
36
+ "@stdlib/strided-base-reinterpret-complex": "^0.1.1",
37
+ "@stdlib/utils-define-nonenumerable-read-only-property": "^0.2.1"
56
38
  },
39
+ "devDependencies": {},
57
40
  "engines": {
58
41
  "node": ">=0.10.0",
59
42
  "npm": ">2.7.0"