diff --git a/CHANGELOG.md b/CHANGELOG.md index 36cf184b..03f27aec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ ##### Features +- [`cbc4d3f`](https://github.com/stdlib-js/stdlib/commit/cbc4d3f7514b7213cad4f9d2ca5d916e13eeffa5) - add `reject` to namespace - [`831de1b`](https://github.com/stdlib-js/stdlib/commit/831de1b4ba21cda245c073a5412bf1a2e9d7598d) - add `map` and `filter` to namespace - [`8b1548f`](https://github.com/stdlib-js/stdlib/commit/8b1548fb45c1ff131f5edac20cb984344a2d28ec) - update namespace TypeScript declarations [(#3190)](https://github.com/stdlib-js/stdlib/pull/3190) @@ -235,6 +236,28 @@ +
+ +#### [@stdlib/ndarray/reject](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/reject) + +
+ +
+ +##### Features + +- [`43ccbfb`](https://github.com/stdlib-js/stdlib/commit/43ccbfbf9cd0ffcdd92fbe6ae0cc60db4f46ea6e) - add `ndarray/reject` + +
+ + + +
+ +
+ + + @@ -271,6 +294,10 @@ A total of 3 people contributed to this release. Thank you to the following cont
+- [`cbc4d3f`](https://github.com/stdlib-js/stdlib/commit/cbc4d3f7514b7213cad4f9d2ca5d916e13eeffa5) - **feat:** add `reject` to namespace _(by Athan Reines)_ +- [`43ccbfb`](https://github.com/stdlib-js/stdlib/commit/43ccbfbf9cd0ffcdd92fbe6ae0cc60db4f46ea6e) - **feat:** add `ndarray/reject` _(by Athan Reines)_ +- [`1cc3e09`](https://github.com/stdlib-js/stdlib/commit/1cc3e095080947f8fdd61ea2217f9b3031b9f93b) - **docs:** fix annotation _(by Athan Reines)_ +- [`7efc6f3`](https://github.com/stdlib-js/stdlib/commit/7efc6f3c8f899974f7d11cb9e06f65f90d5caaa9) - **bench:** fix symbol name _(by Athan Reines)_ - [`17430f4`](https://github.com/stdlib-js/stdlib/commit/17430f4a7f15da00c9288b2b4d0577b6b7f8007f) - **docs:** add note _(by Athan Reines)_ - [`354a147`](https://github.com/stdlib-js/stdlib/commit/354a1472bd69ab26c020aa7ba1df043c88e985b2) - **docs:** add note _(by Athan Reines)_ - [`80542fd`](https://github.com/stdlib-js/stdlib/commit/80542fd459075dc2c49f6e529a21bd661129899e) - **docs:** remove note _(by Athan Reines)_ diff --git a/filter/benchmark/benchmark.2d.js b/filter/benchmark/benchmark.2d.js index 7bbb0a20..76d61d95 100644 --- a/filter/benchmark/benchmark.2d.js +++ b/filter/benchmark/benchmark.2d.js @@ -30,7 +30,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); var shape2strides = require( './../../base/shape2strides' ); var ndarray = require( './../../ctor' ); var pkg = require( './../package.json' ).name; -var map = require( './../lib' ); +var filter = require( './../lib' ); // VARIABLES // @@ -94,7 +94,7 @@ function createBenchmark( len, shape, xtype, ytype, order ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - y = map( x, opts, predicate ); + y = filter( x, opts, predicate ); if ( isnan( y.data[ i%y.length ] ) ) { b.fail( 'should not return NaN' ); } diff --git a/filter/lib/main.js b/filter/lib/main.js index 892c4228..674f5d3e 100644 --- a/filter/lib/main.js +++ b/filter/lib/main.js @@ -44,7 +44,7 @@ var format = require( '@stdlib/string/format' ); * @param {ndarray} x - input ndarray * @param {Options} [options] - function options * @param {string} [options.dtype] - output array data type -* @param {boolean} [options.order='row-major'] - index iteration order +* @param {boolean} [options.order] - index iteration order * @param {Callback} predicate - predicate function * @param {*} [thisArg] - predicate execution context * @throws {TypeError} first argument must be an ndarray-like object diff --git a/lib/index.js b/lib/index.js index 7996c30e..41a26821 100644 --- a/lib/index.js +++ b/lib/index.js @@ -369,6 +369,15 @@ setReadOnly( ns, 'outputDataTypePolicies', require( './../output-dtype-policies' */ setReadOnly( ns, 'promotionRules', require( './../promotion-rules' ) ); +/** +* @name reject +* @memberof ns +* @readonly +* @type {Function} +* @see {@link module:@stdlib/ndarray/reject} +*/ +setReadOnly( ns, 'reject', require( './../reject' ) ); + /** * @name safeCasts * @memberof ns diff --git a/reject/README.md b/reject/README.md new file mode 100644 index 00000000..c9f69c19 --- /dev/null +++ b/reject/README.md @@ -0,0 +1,190 @@ + + +# reject + +> Return a shallow copy of an [ndarray][@stdlib/ndarray/ctor] containing only those elements which fail a test implemented by a predicate function. + +
+ +
+ + + +
+ +## Usage + +```javascript +var reject = require( '@stdlib/ndarray/reject' ); +``` + +#### reject( x\[, options], predicate\[, thisArg] ) + +Returns a shallow copy of an [ndarray][@stdlib/ndarray/ctor] containing only those elements which fail a test implemented by a `predicate` function. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function predicate( z ) { + return z <= 6.0; +} + +var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +var shape = [ 2, 3 ]; +var strides = [ 6, 1 ]; +var offset = 1; + +var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +// returns + +var y = reject( x, predicate ); +// returns + +var arr = ndarray2array( y ); +// returns [ 8.0, 9.0, 10.0 ] +``` + +The function accepts the following arguments: + +- **x**: input [ndarray][@stdlib/ndarray/ctor]. +- **options**: function options. +- **predicate**: predicate function. +- **thisArg**: predicate function execution context. + +The function accepts the following options: + +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. If not specified, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. +- **order**: index iteration order. By default, the function iterates over elements according to the [layout order][@stdlib/ndarray/orders] of the provided [ndarray][@stdlib/ndarray/ctor]. Accordingly, for row-major input [ndarrays][@stdlib/ndarray/ctor], the last dimension indices increment fastest. For column-major input [ndarrays][@stdlib/ndarray/ctor], the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input [ndarray][@stdlib/ndarray/ctor]'s layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input [ndarray][@stdlib/ndarray/ctor] may, in some circumstances, result in performance degradation due to cache misses. Must be either `'row-major'` or `'column-major'`. + +By default, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. To return an ndarray with a different [data type][@stdlib/ndarray/dtypes], specify the `dtype` option. + + + +```javascript +var Float64Array = require( '@stdlib/array/float64' ); +var ndarray = require( '@stdlib/ndarray/ctor' ); +var dtype = require( '@stdlib/ndarray/dtype' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); + +function predicate( z ) { + return z <= 6.0; +} + +var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +var shape = [ 2, 3 ]; +var strides = [ 6, 1 ]; +var offset = 1; + +var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +// returns + +var opts = { + 'dtype': 'float32' +}; +var y = reject( x, opts, predicate ); +// returns + +var dt = dtype( y ); +// returns 'float32' + +var arr = ndarray2array( y ); +// returns [ 8.0, 9.0, 10.0 ] +``` + +The `predicate` function is provided the following arguments: + +- **value**: current array element. +- **indices**: current array element indices. +- **arr**: the input [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Notes + +- The function does **not** perform explicit casting (e.g., from a real-valued floating-point number to a complex floating-point number). Any such casting should be performed **prior to** calling this function. +- The function **always** returns a one-dimensional [ndarray][@stdlib/ndarray/ctor]. + +
+ + + +
+ +## Examples + + + +```javascript +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( '@stdlib/ndarray/to-array' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var array = require( '@stdlib/ndarray/array' ); +var isPositive = require( '@stdlib/assert/is-positive-number' ).isPrimitive; +var reject = require( '@stdlib/ndarray/reject' ); + +var buffer = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = array( buffer, { + 'shape': [ 5, 2 ], + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = reject( x, naryFunction( isPositive, 1 ) ); +console.log( ndarray2array( y ) ); +``` + +
+ + + + + + + + + + + + diff --git a/reject/benchmark/benchmark.1d.js b/reject/benchmark/benchmark.1d.js new file mode 100644 index 00000000..a096fd09 --- /dev/null +++ b/reject/benchmark/benchmark.1d.js @@ -0,0 +1,150 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( './../../base/shape2strides' ); +var ndarray = require( './../../ctor' ); +var pkg = require( './../package.json' ).name; +var reject = require( './../lib' ); + + +// VARIABLES // + +var xtypes = [ 'generic' ]; +var ytypes = [ 'float64' ]; +var orders = [ 'row-major', 'column-major' ]; + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {number} value - array element +* @param {NonNegativeIntegerArray} indices - element indices +* @param {ndarray} arr - input array +* @returns {boolean} result +*/ +function predicate( value ) { + return value > 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @param {string} order - ndarray memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype, order ) { + var strides; + var opts; + var xbuf; + var x; + + xbuf = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + strides = shape2strides( shape, order ); + x = ndarray( xtype, xbuf, shape, strides, 0, order ); + opts = { + 'dtype': ytype + }; + + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = reject( x, opts, predicate ); + if ( isnan( y.data[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var ord; + var sh; + var t1; + var t2; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < orders.length; k++ ) { + ord = orders[ k ]; + for ( j = 0; j < xtypes.length; j++ ) { + t1 = xtypes[ j ]; + t2 = ytypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); + } + } + } +} + +main(); diff --git a/reject/benchmark/benchmark.2d.js b/reject/benchmark/benchmark.2d.js new file mode 100644 index 00000000..5fe64511 --- /dev/null +++ b/reject/benchmark/benchmark.2d.js @@ -0,0 +1,161 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var sqrt = require( '@stdlib/math/base/special/sqrt' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var shape2strides = require( './../../base/shape2strides' ); +var ndarray = require( './../../ctor' ); +var pkg = require( './../package.json' ).name; +var reject = require( './../lib' ); + + +// VARIABLES // + +var xtypes = [ 'generic' ]; +var ytypes = [ 'float64' ]; +var orders = [ 'row-major', 'column-major' ]; + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {number} value - array element +* @param {NonNegativeIntegerArray} indices - element indices +* @param {ndarray} arr - input array +* @returns {boolean} result +*/ +function predicate( value ) { + return value > 0.0; +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - ndarray length +* @param {NonNegativeIntegerArray} shape - ndarray shape +* @param {string} xtype - input ndarray data type +* @param {string} ytype - output ndarray data type +* @param {string} order - ndarray memory layout +* @returns {Function} benchmark function +*/ +function createBenchmark( len, shape, xtype, ytype, order ) { + var strides; + var opts; + var xbuf; + var x; + var y; + + xbuf = discreteUniform( len, -100, 100, { + 'dtype': xtype + }); + strides = shape2strides( shape, order ); + x = ndarray( xtype, xbuf, shape, strides, 0, order ); + opts = { + 'dtype': ytype + }; + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = reject( x, opts, predicate ); + if ( isnan( y.data[ i%y.length ] ) ) { + b.fail( 'should not return NaN' ); + } + } + b.toc(); + if ( !isndarrayLike( y ) ) { + b.fail( 'should return an ndarray' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var ord; + var sh; + var t1; + var t2; + var f; + var i; + var j; + var k; + + min = 1; // 10^min + max = 6; // 10^max + + for ( k = 0; k < orders.length; k++ ) { + ord = orders[ k ]; + for ( j = 0; j < xtypes.length; j++ ) { + t1 = xtypes[ j ]; + t2 = ytypes[ j ]; + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + + sh = [ len/2, 2 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); + + sh = [ 2, len/2 ]; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); + + len = floor( sqrt( len ) ); + sh = [ len, len ]; + len *= len; + f = createBenchmark( len, sh, t1, t2, ord ); + bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+ord+',yorder='+ord+',xtype='+t1+',ytype='+t2, f ); + } + } + } +} + +main(); diff --git a/reject/docs/repl.txt b/reject/docs/repl.txt new file mode 100644 index 00000000..fd0e935d --- /dev/null +++ b/reject/docs/repl.txt @@ -0,0 +1,51 @@ + +{{alias}}( x[, options], predicate[, thisArg] ) + Returns a shallow copy of an ndarray containing only those elements which + fail a test implemented by a predicate function. + + The predicate function is provided the following arguments: + + - value: current array element. + - indices: current array element indices. + - arr: the input ndarray. + + Parameters + ---------- + x: ndarray + Input ndarray. + + options: Object (optional) + Function options. + + options.dtype: string (optional) + Output ndarray data type. Overrides using the input array's inferred + data type. + + options.order: string (optional) + Index iteration order. By default, the function iterates over elements + according to the layout order of the provided array. Accordingly, for + row-major input arrays, the last dimension indices increment fastest. + For column-major input arrays, the first dimension indices increment + fastest. To override the inferred order and ensure that indices + increment in a specific manor, regardless of the input array's layout + order, explicitly set the iteration order. Note, however, that iterating + according to an order which does not match that of the input array may, + in some circumstances, result in performance degradation due to cache + misses. Must be either 'row-major' or 'column-major'. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Predicate function execution context. + + Examples + -------- + > var x = {{alias:@stdlib/ndarray/array}}( [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ); + > function f( v ) { return v <= 2.0; }; + > var y = {{alias}}( x, f ); + > {{alias:@stdlib/ndarray/to-array}}( y ) + [ 3.0, 4.0 ] + + See Also + -------- diff --git a/reject/docs/types/index.d.ts b/reject/docs/types/index.d.ts new file mode 100644 index 00000000..b42a2f7b --- /dev/null +++ b/reject/docs/types/index.d.ts @@ -0,0 +1,1612 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +/* eslint-disable max-lines */ + +import { typedndarray, DataType, Order, float64ndarray, float32ndarray, complex128ndarray, complex64ndarray, int32ndarray, int16ndarray, int8ndarray, uint32ndarray, uint16ndarray, uint8ndarray, uint8cndarray, boolndarray, genericndarray } from '@stdlib/types/ndarray'; +import { Complex64, Complex128 } from '@stdlib/types/complex'; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an element passes a test +*/ +type Nullary = ( this: V ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element passes a test +*/ +type Unary = ( this: V, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @returns boolean indicating whether an element passes a test +*/ +type Binary = ( this: V, value: T, indices: Array ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Ternary = ( this: V, value: T, indices: Array, arr: typedndarray ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param indices - current array element indices +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing "base" function options. +*/ +interface BaseOptions { + /** + * Index iteration order. + * + * ## Notes + * + * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. + */ + order?: Order; +} + +/** +* Interface describing function options. +*/ +interface OrderOptions { + /** + * Index iteration order. + * + * ## Notes + * + * - By default, the function iterates over elements according to the layout order of the provided ndarray. Accordingly, for row-major input ndarrays, the last dimension indices increment fastest. For column-major input ndarrays, the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manor, regardless of the input ndarray's layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input ndarray may, in some circumstances, result in performance degradation due to cache misses. + */ + order: Order; +} + +/** +* Interface describing function options. +*/ +interface Options extends BaseOptions { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: DataType; +} + +/** +* Interface describing function options. +*/ +interface Float64Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'float64'; +} + +/** +* Interface describing function options. +*/ +interface Float32Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'float32'; +} + +/** +* Interface describing function options. +*/ +interface Complex128Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'complex128'; +} + +/** +* Interface describing function options. +*/ +interface Complex64Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'complex64'; +} + +/** +* Interface describing function options. +*/ +interface Int32Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'int32'; +} + +/** +* Interface describing function options. +*/ +interface Int16Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'int16'; +} + +/** +* Interface describing function options. +*/ +interface Int8Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'int8'; +} + +/** +* Interface describing function options. +*/ +interface Uint32Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'uint32'; +} + +/** +* Interface describing function options. +*/ +interface Uint16Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'uint16'; +} + +/** +* Interface describing function options. +*/ +interface Uint8Options extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'uint8'; +} + +/** +* Interface describing function options. +*/ +interface Uint8COptions extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'uint8c'; +} + +/** +* Interface describing function options. +*/ +interface BoolOptions extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'bool'; +} + +/** +* Interface describing function options. +*/ +interface GenericOptions extends Options { + /** + * Output ndarray data type. + * + * ## Notes + * + * - This option overrides using the input ndarray's inferred data type. + */ + dtype?: 'generic'; +} + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: float64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: float32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, predicate ); +* // returns +*/ +declare function reject( x: complex64ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, predicate ); +* // returns +*/ +declare function reject( x: complex128ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int32Array = require( '@stdlib/array/int32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int16Array = require( '@stdlib/array/int16' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int8Array = require( '@stdlib/array/int8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint32Array = require( '@stdlib/array/uint32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint32ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint16Array = require( '@stdlib/array/uint16' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint16ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint8ndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint8cndarray, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function predicate( v ) { +* return !v; +* } +* +* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, predicate ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ true, true, true, true ] +*/ +declare function reject( x: boolndarray, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: genericndarray, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: float64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float32Array = require( '@stdlib/array/float32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: float32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex64Array = require( '@stdlib/array/complex64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, predicate ); +* // returns +*/ +declare function reject( x: complex64ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 0; +* +* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, predicate ); +* // returns +*/ +declare function reject( x: complex128ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int32Array = require( '@stdlib/array/int32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int16Array = require( '@stdlib/array/int16' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Int8Array = require( '@stdlib/array/int8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Int8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'int8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: int8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint32Array = require( '@stdlib/array/uint32' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint32Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint32', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint32ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint16Array = require( '@stdlib/array/uint16' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint16Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint16', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint16ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint8Array = require( '@stdlib/array/uint8' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint8Array( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint8', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint8ndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Uint8ClampedArray = require( '@stdlib/array/uint8c' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Uint8ClampedArray( [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'uint8c', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: uint8cndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var BooleanArray = require( '@stdlib/array/bool' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function predicate( v ) { +* return !v; +* } +* +* var buffer = new BooleanArray( [ false, true, false, true, false, true, false, true, false, true, false, true ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'bool', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, predicate ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ true, true, true, true ] +*/ +declare function reject( x: boolndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - function options +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ]; +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'generic', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'order': 'row-major' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: genericndarray, options: OrderOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'float64' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: typedndarray, options: Float64Options, predicate: Predicate, thisArg?: ThisParameterType> ): float64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'float32' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: typedndarray, options: Float32Options, predicate: Predicate, thisArg?: ThisParameterType> ): float32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'complex128' +* }; +* var y = reject( x, opts, predicate ); +* // returns +*/ +declare function reject( x: typedndarray, options: Complex128Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex128ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var Complex128Array = require( '@stdlib/array/complex128' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* function predicate( z, idx ) { +* return idx[ 0 ] > 0; +* } +* +* var buffer = new Complex128Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 3, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'complex128', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'complex64' +* }; +* var y = reject( x, opts, predicate ); +* // returns +*/ +declare function reject( x: typedndarray, options: Complex64Options, predicate: Predicate, thisArg?: ThisParameterType> ): complex64ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'int32' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Int32Options, predicate: Predicate, thisArg?: ThisParameterType> ): int32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'int16' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Int16Options, predicate: Predicate, thisArg?: ThisParameterType> ): int16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'int8' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Int8Options, predicate: Predicate, thisArg?: ThisParameterType> ): int8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'uint32' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Uint32Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint32ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'uint16' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Uint16Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint16ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'uint8' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Uint8Options, predicate: Predicate, thisArg?: ThisParameterType> ): uint8ndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'uint8c' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2, 4, 8, 10 ] +*/ +declare function reject( x: typedndarray, options: Uint8COptions, predicate: Predicate, thisArg?: ThisParameterType> ): uint8cndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'bool' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ true, true, true, true ] +*/ +declare function reject( x: typedndarray, options: BoolOptions, predicate: Predicate, thisArg?: ThisParameterType> ): boolndarray; + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param x - input ndarray +* @param options - options +* @param options.dtype - output ndarray data type +* @param options.order - iteration order +* @param predicate - predicate function +* @param thisArg - predicate function execution context +* @returns output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var opts = { +* 'dtype': 'generic' +* }; +* var y = reject( x, opts, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +declare function reject( x: typedndarray, options: GenericOptions, predicate: Predicate, thisArg?: ThisParameterType> ): genericndarray; + + +// EXPORTS // + +export = reject; diff --git a/reject/docs/types/test.ts b/reject/docs/types/test.ts new file mode 100644 index 00000000..eaf4dff6 --- /dev/null +++ b/reject/docs/types/test.ts @@ -0,0 +1,195 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +/// + +import empty = require( './../../../base/empty' ); +import zeros = require( './../../../base/zeros' ); +import reject = require( './index' ); + +/** +* Predicate function. +* +* @param x - input value +* @returns result +*/ +function predicate( x: any ): boolean { + return Boolean( x ); +} + +// The function returns an ndarray... +{ + const sh = [ 2, 2 ]; + const ord = 'row-major'; + + reject( zeros( 'float64', sh, ord ), predicate ); // $ExpectType float64ndarray + reject( zeros( 'float64', sh, ord ), predicate, {} ); // $ExpectType float64ndarray + reject( zeros( 'float32', sh, ord ), predicate ); // $ExpectType float32ndarray + reject( zeros( 'float32', sh, ord ), predicate, {} ); // $ExpectType float32ndarray + reject( zeros( 'complex64', sh, ord ), predicate ); // $ExpectType complex64ndarray + reject( zeros( 'complex64', sh, ord ), predicate, {} ); // $ExpectType complex64ndarray + reject( zeros( 'complex128', sh, ord ), predicate ); // $ExpectType complex128ndarray + reject( zeros( 'complex128', sh, ord ), predicate, {} ); // $ExpectType complex128ndarray + reject( zeros( 'int32', sh, ord ), predicate ); // $ExpectType int32ndarray + reject( zeros( 'int32', sh, ord ), predicate, {} ); // $ExpectType int32ndarray + reject( zeros( 'int16', sh, ord ), predicate ); // $ExpectType int16ndarray + reject( zeros( 'int16', sh, ord ), predicate, {} ); // $ExpectType int16ndarray + reject( zeros( 'int8', sh, ord ), predicate ); // $ExpectType int8ndarray + reject( zeros( 'int8', sh, ord ), predicate, {} ); // $ExpectType int8ndarray + reject( zeros( 'uint32', sh, ord ), predicate ); // $ExpectType uint32ndarray + reject( zeros( 'uint32', sh, ord ), predicate, {} ); // $ExpectType uint32ndarray + reject( zeros( 'uint16', sh, ord ), predicate ); // $ExpectType uint16ndarray + reject( zeros( 'uint16', sh, ord ), predicate, {} ); // $ExpectType uint16ndarray + reject( zeros( 'uint8', sh, ord ), predicate ); // $ExpectType uint8ndarray + reject( zeros( 'uint8', sh, ord ), predicate, {} ); // $ExpectType uint8ndarray + reject( zeros( 'uint8c', sh, ord ), predicate ); // $ExpectType uint8cndarray + reject( zeros( 'uint8c', sh, ord ), predicate, {} ); // $ExpectType uint8cndarray + reject( empty( 'bool', sh, ord ), predicate ); // $ExpectType boolndarray + reject( empty( 'bool', sh, ord ), predicate, {} ); // $ExpectType boolndarray + reject( zeros( 'generic', sh, ord ), predicate ); // $ExpectType genericndarray + reject( zeros( 'generic', sh, ord ), predicate, {} ); // $ExpectType genericndarray + + + reject( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate ); // $ExpectType float64ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'float64' }, predicate, {} ); // $ExpectType float64ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate ); // $ExpectType float32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'float32' }, predicate, {} ); // $ExpectType float32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate ); // $ExpectType complex64ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'complex64' }, predicate, {} ); // $ExpectType complex64ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate ); // $ExpectType complex128ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'complex128' }, predicate, {} ); // $ExpectType complex128ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate ); // $ExpectType int32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int32' }, predicate, {} ); // $ExpectType int32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate ); // $ExpectType int16ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int16' }, predicate, {} ); // $ExpectType int16ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate ); // $ExpectType int8ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'int8' }, predicate, {} ); // $ExpectType int8ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate ); // $ExpectType uint32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint32' }, predicate, {} ); // $ExpectType uint32ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate ); // $ExpectType uint16ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint16' }, predicate, {} ); // $ExpectType uint16ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate ); // $ExpectType uint8ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint8' }, predicate, {} ); // $ExpectType uint8ndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate ); // $ExpectType uint8cndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'uint8c' }, predicate, {} ); // $ExpectType uint8cndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate ); // $ExpectType boolndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'bool' }, predicate, {} ); // $ExpectType boolndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate ); // $ExpectType genericndarray + reject( zeros( 'generic', sh, ord ), { 'dtype': 'generic' }, predicate, {} ); // $ExpectType genericndarray + + + reject( zeros( 'float64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float64ndarray + reject( zeros( 'float64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float64ndarray + reject( zeros( 'float32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType float32ndarray + reject( zeros( 'float32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType float32ndarray + reject( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex64ndarray + reject( zeros( 'complex64', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex64ndarray + reject( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate ); // $ExpectType complex128ndarray + reject( zeros( 'complex128', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType complex128ndarray + reject( zeros( 'int32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int32ndarray + reject( zeros( 'int32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int32ndarray + reject( zeros( 'int16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int16ndarray + reject( zeros( 'int16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int16ndarray + reject( zeros( 'int8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType int8ndarray + reject( zeros( 'int8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType int8ndarray + reject( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint32ndarray + reject( zeros( 'uint32', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint32ndarray + reject( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint16ndarray + reject( zeros( 'uint16', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint16ndarray + reject( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8ndarray + reject( zeros( 'uint8', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8ndarray + reject( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate ); // $ExpectType uint8cndarray + reject( zeros( 'uint8c', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType uint8cndarray + reject( empty( 'bool', sh, ord ), { 'order': ord }, predicate ); // $ExpectType boolndarray + reject( empty( 'bool', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType boolndarray + reject( zeros( 'generic', sh, ord ), { 'order': ord }, predicate ); // $ExpectType genericndarray + reject( zeros( 'generic', sh, ord ), { 'order': ord }, predicate, {} ); // $ExpectType genericndarray + +} + +// The compiler throws an error if the function is provided a first argument which is not an ndarray... +{ + reject( 5, predicate ); // $ExpectError + reject( true, predicate ); // $ExpectError + reject( false, predicate ); // $ExpectError + reject( null, predicate ); // $ExpectError + reject( undefined, predicate ); // $ExpectError + reject( {}, predicate ); // $ExpectError + reject( [ 1 ], predicate ); // $ExpectError + reject( ( x: number ): number => x, predicate ); // $ExpectError +} + +// The compiler throws an error if the function is provided a callback which is not a function... +{ + const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + reject( x, '5' ); // $ExpectError + reject( x, true ); // $ExpectError + reject( x, false ); // $ExpectError + reject( x, null ); // $ExpectError + reject( x, undefined ); // $ExpectError + reject( x, {} ); // $ExpectError + reject( x, [ 1 ] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an options argument which is not an object... +{ + const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + reject( x, '10', predicate, {} ); // $ExpectError + reject( x, 10, predicate, {} ); // $ExpectError + reject( x, false, predicate, {} ); // $ExpectError + reject( x, true, predicate, {} ); // $ExpectError + reject( x, [], predicate, {} ); // $ExpectError + reject( x, ( x: number ): number => x, predicate, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided a `dtype` option which is not a valid data type... +{ + const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + reject( x, { 'dtype': '10' }, predicate ); // $ExpectError + reject( x, { 'dtype': 10 }, predicate ); // $ExpectError + reject( x, { 'dtype': null }, predicate ); // $ExpectError + reject( x, { 'dtype': false }, predicate ); // $ExpectError + reject( x, { 'dtype': true }, predicate ); // $ExpectError + reject( x, { 'dtype': [] }, predicate ); // $ExpectError + reject( x, { 'dtype': {} }, predicate ); // $ExpectError + reject( x, { 'dtype': ( x: number ): number => x }, predicate ); // $ExpectError +} + +// The compiler throws an error if the function is provided an `order` option which is not a valid order... +{ + const x = zeros( 'generic', [ 2, 2 ], 'row-major' ); + + reject( x, { 'order': '10' }, predicate ); // $ExpectError + reject( x, { 'order': 10 }, predicate ); // $ExpectError + reject( x, { 'order': null }, predicate ); // $ExpectError + reject( x, { 'order': false }, predicate ); // $ExpectError + reject( x, { 'order': true }, predicate ); // $ExpectError + reject( x, { 'order': [] }, predicate ); // $ExpectError + reject( x, { 'order': {} }, predicate ); // $ExpectError + reject( x, { 'order': ( x: number ): number => x }, predicate ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + reject(); // $ExpectError + reject( zeros( 'float64', [ 2, 2 ], 'row-major' ) ); // $ExpectError + reject( zeros( 'float64', [ 2, 2 ], 'row-major' ), {}, ( x: number ): number => x, {}, {} ); // $ExpectError +} diff --git a/reject/examples/index.js b/reject/examples/index.js new file mode 100644 index 00000000..35b180d7 --- /dev/null +++ b/reject/examples/index.js @@ -0,0 +1,38 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); +var ndarray2array = require( './../../to-array' ); +var naryFunction = require( '@stdlib/utils/nary-function' ); +var array = require( './../../array' ); +var isPositive = require( '@stdlib/assert/is-positive-number' ).isPrimitive; +var reject = require( './../lib' ); + +var buffer = discreteUniform( 10, -100, 100, { + 'dtype': 'generic' +}); +var x = array( buffer, { + 'shape': [ 5, 2 ], + 'dtype': 'generic' +}); +console.log( ndarray2array( x ) ); + +var y = reject( x, naryFunction( isPositive, 1 ) ); +console.log( ndarray2array( y ) ); diff --git a/reject/lib/index.js b/reject/lib/index.js new file mode 100644 index 00000000..6f6b1223 --- /dev/null +++ b/reject/lib/index.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @module @stdlib/ndarray/reject +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* var reject = require( '@stdlib/ndarray/reject' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/reject/lib/main.js b/reject/lib/main.js new file mode 100644 index 00000000..f3f390bc --- /dev/null +++ b/reject/lib/main.js @@ -0,0 +1,199 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); +var isOrder = require( './../../base/assert/is-order' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var ctors = require( './../../base/buffer-ctors' ); +var zeros = require( '@stdlib/array/base/zeros' ); +var getShape = require( './../../shape' ); +var getDType = require( './../../dtype' ); +var getOrder = require( './../../order' ); +var numel = require( './../../base/numel' ); +var nextCartesianIndex = require( './../../base/next-cartesian-index' ).assign; +var gcopy = require( '@stdlib/blas/base/gcopy' ); +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Returns a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function. +* +* @param {ndarray} x - input ndarray +* @param {Options} [options] - function options +* @param {string} [options.dtype] - output array data type +* @param {boolean} [options.order] - index iteration order +* @param {Callback} predicate - predicate function +* @param {*} [thisArg] - predicate execution context +* @throws {TypeError} first argument must be an ndarray-like object +* @throws {TypeError} callback argument must be a function +* @throws {TypeError} options argument must be an object +* @returns {ndarray} output ndarray +* +* @example +* var isOdd = require( '@stdlib/assert/is-odd' ).isPrimitive; +* var Float64Array = require( '@stdlib/array/float64' ); +* var ndarray = require( '@stdlib/ndarray/ctor' ); +* var ndarray2array = require( '@stdlib/ndarray/to-array' ); +* +* var buffer = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ); +* var shape = [ 2, 3 ]; +* var strides = [ 6, 1 ]; +* var offset = 1; +* +* var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' ); +* // returns +* +* var y = reject( x, isOdd ); +* // returns +* +* var arr = ndarray2array( y ); +* // returns [ 2.0, 4.0, 8.0, 10.0 ] +*/ +function reject( x, options, predicate, thisArg ) { + var hasOpts; + var ndims; + var cache; + var clbk; + var opts; + var ctor; + var cidx; + var ctx; + var ord; + var dim; + var idx; + var buf; + var dt; + var sh; + var N; + var y; + var v; + var i; + if ( !isndarrayLike( x ) ) { + throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) ); + } + if ( arguments.length < 3 ) { + clbk = options; + } else if ( arguments.length === 3 ) { + if ( isFunction( options ) ) { + clbk = options; + ctx = predicate; + } else { + hasOpts = true; + opts = options; + clbk = predicate; + } + } else { + hasOpts = true; + opts = options; + clbk = predicate; + ctx = thisArg; + } + if ( !isFunction( clbk ) ) { + throw new TypeError( format( 'invalid argument. Callback argument must be a function. Value: `%s`.', clbk ) ); + } + if ( hasOpts ) { + if ( !isPlainObject( opts ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', opts ) ); + } + if ( hasOwnProp( opts, 'dtype' ) ) { + dt = opts.dtype; + } else { + dt = getDType( x ); + } + if ( hasOwnProp( opts, 'order' ) ) { + if ( !isOrder( opts.order ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be a recognized order. Option: `%s`.', 'order', opts.order ) ); + } + ord = opts.order; + } + } else { + dt = getDType( x ); + } + // Resolve an output array buffer constructor: + ctor = ctors( dt ); + if ( ctor === null ) { + // The only way we should get here is if the user provided an unsupported data type, as `getDType` should error if the input array has an unrecognized/unsupported data type... + throw new TypeError( format( 'invalid option. `%s` option must be a recognized data type. Option: `%s`.', 'dtype', opts.dtype ) ); + } + // Resolve the iteration order: + if ( ord === void 0 ) { + ord = getOrder( x ); + } + // Resolve the input array shape: + sh = getShape( x ); + + // Compute the number of array elements: + N = numel( sh ); + + // Retrieve the number of dimensions: + ndims = sh.length; + + // Resolve the dimension in which indices should iterate fastest: + if ( ord === 'row-major' ) { + dim = ndims - 1; + } else { // ord === 'column-major' + dim = 0; + } + // Initialize an index array workspace: + idx = zeros( ndims ); + + // Initialize a value cache for those elements which pass a predicate function (note: unfortunately, we use an associative array here, as no other good options. If we use a "generic" array, we are limited to 2^32-1 elements. If we allocate, say, a Float64Array buffer for storing indices, we risk materializing lazily-materialized input ndarray values again (e.g., lazy accessor ndarray), which could be expensive. If we allocate a workspace buffer of equal size to the input ndarray to store materialized values, we'd then need to perform another copy in order to shrink the buffer, as, otherwise, could be holding on to significantly more memory than needed for the returned ndarray. There are likely other options, but all involve complexity, so the simplest option is used here.): + cache = { + 'length': 0 + }; + + // Filter elements according to a predicate function... + cidx = -1; + for ( i = 0; i < N; i++ ) { + if ( i > 0 ) { + idx = nextCartesianIndex( sh, ord, idx, dim, idx ); + } + v = x.get.apply( x, idx ); + if ( !clbk.call( ctx, v, idx.slice(), x ) ) { + cache.length += 1; + cidx += 1; + cache[ cidx ] = v; + } + } + // Retrieve the number of cached elements: + N = cache.length; + + // Allocate an output array buffer: + buf = new ctor( N ); + + // Copy cached elements to the output array buffer: + gcopy( N, cache, 1, buf, 1 ); + + // Create an output ndarray: + y = new x.constructor( dt, buf, [ N ], [ 1 ], 0, ord ); + + return y; +} + + +// EXPORTS // + +module.exports = reject; diff --git a/reject/package.json b/reject/package.json new file mode 100644 index 00000000..352dab5e --- /dev/null +++ b/reject/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/ndarray/reject", + "version": "0.0.0", + "description": "Return a shallow copy of an ndarray containing only those elements which fail a test implemented by a predicate function.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "strided", + "array", + "ndarray", + "filter", + "reject", + "extract", + "copy", + "select", + "take" + ], + "__stdlib__": {} +} diff --git a/reject/test/test.js b/reject/test/test.js new file mode 100644 index 00000000..324c5ada --- /dev/null +++ b/reject/test/test.js @@ -0,0 +1,892 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var ones = require( '@stdlib/array/ones' ); +var ndarray = require( './../../ctor' ); +var shape2strides = require( './../../base/shape2strides' ); +var strides2offset = require( './../../base/strides2offset' ); +var Float64Array = require( '@stdlib/array/float64' ); +var Float32Array = require( '@stdlib/array/float32' ); +var isSameFloat64Array = require( '@stdlib/assert/is-same-float64array' ); +var isSameFloat32Array = require( '@stdlib/assert/is-same-float32array' ); +var reject = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reject, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an ndarray', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + [], + {}, + function noop() {}, + { + 'data': true + } + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + reject( value, predicate ); + }; + } + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function throws an error if a callback argument which is not a function', function test( t ) { + var values; + var x; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + {}, + [] + ]; + x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + reject( x, value ); + }; + } +}); + +tape( 'the function throws an error if callback argument which is not a function (options)', function test( t ) { + var values; + var opts; + var x; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + {}, + [] + ]; + x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + opts = { + 'dtype': 'float64' + }; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided ' + values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + reject( x, opts, value ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var x; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + [] + ]; + x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+ values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + reject( x, value, predicate ); + }; + } + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function throws an error if provided an invalid `dtype` option', function test( t ) { + var values; + var x; + var i; + + values = [ + 'foo', + 'bar', + 1, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+ values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts = { + 'dtype': value + }; + reject( x, opts, predicate ); + }; + } + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function throws an error if provided an invalid `order` option', function test( t ) { + var values; + var x; + var i; + + values = [ + 'foo', + 'bar', + 1, + NaN, + true, + false, + void 0, + null, + [], + {}, + function noop() {} + ]; + x = ndarray( 'generic', ones( 4, 'generic' ), [ 2, 2 ], [ 2, 1 ], 0, 'row-major' ); + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+ values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + var opts = { + 'order': value + }; + reject( x, opts, predicate ); + }; + } + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function filters an array according to a predicate function (row-major)', function test( t ) { + var expected; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + y = reject( x, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function filters an array according to a predicate function (column-major, contiguous)', function test( t ) { + var expected; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + y = reject( x, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function filters an array according to a predicate function (row-major, contiguous, options)', function test( t ) { + var expected; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + x = ndarray( dt, buf, sh, st, o, ord ); + + opts = {}; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + opts = { + 'dtype': 'float32' + }; + y = reject( x, opts, predicate ); + + expected = new Float32Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function filters an array according to a predicate function (column-major, contiguous, options)', function test( t ) { + var expected; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + x = ndarray( dt, buf, sh, st, o, ord ); + + opts = {}; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + opts = { + 'dtype': 'float32' + }; + y = reject( x, opts, predicate ); + + expected = new Float32Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat32Array( y.data, expected ), true, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + return ( z < 0.0 ); + } +}); + +tape( 'the function supports providing a callback execution context', function test( t ) { + var expected; + var ctx; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + ctx = { + 'count': 0 + }; + y = reject( x, predicate, ctx ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( z < 0.0 ); + } +}); + +tape( 'the function supports providing a callback execution context (options)', function test( t ) { + var expected; + var ctx; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + ctx = { + 'count': 0 + }; + y = reject( x, {}, predicate, ctx ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + + t.end(); + + function predicate( z ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( z < 0.0 ); + } +}); + +tape( 'the function invokes a provided callback with three arguments (row-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + y = reject( x, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +}); + +tape( 'the function invokes a provided callback with three arguments (column-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + y = reject( x, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +}); + +tape( 'the function supports specifying the iteration order (row-major/row-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + opts = { + 'order': 'row-major' + }; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +}); + +tape( 'the function supports specifying the iteration order (row-major/column-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'row-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + opts = { + 'order': 'column-major' + }; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +}); + +tape( 'the function supports specifying the iteration order (column-major/row-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + opts = { + 'order': 'row-major' + }; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 0 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +}); + +tape( 'the function supports specifying the iteration order (column-major/column-major)', function test( t ) { + var expected; + var indices; + var values; + var arrays; + var opts; + var ord; + var buf; + var sh; + var st; + var dt; + var o; + var x; + var y; + var i; + + buf = new Float64Array( [ 1.0, -2.0, 3.0, -4.0 ] ); + dt = 'float64'; + ord = 'column-major'; + sh = [ 2, 1, 2 ]; + st = shape2strides( sh, ord ); + o = strides2offset( sh, st ); + + x = ndarray( dt, buf, sh, st, o, ord ); + + values = []; + indices = []; + arrays = []; + + opts = { + 'order': 'column-major' + }; + y = reject( x, opts, predicate ); + + expected = new Float64Array([ + 1.0, + 3.0 + ]); + t.strictEqual( isSameFloat64Array( y.data, expected ), true, 'returns expected value' ); + + expected = [ + [ 0, 0, 0 ], + [ 1, 0, 0 ], + [ 0, 0, 1 ], + [ 1, 0, 1 ] + ]; + t.deepEqual( indices, expected, 'returns expected value' ); + + expected = [ + x, + x, + x, + x + ]; + for ( i = 0; i < expected.length; i++ ) { + t.strictEqual( arrays[ i ], expected[ i ], 'returns expected value' ); + } + + t.end(); + + function predicate( z, idx, arr ) { + values.push( z ); + indices.push( idx ); + arrays.push( arr ); + return ( z < 0.0 ); + } +});