Skip to content

Commit 928bb32

Browse files
committed
Auto-generated commit
1 parent 7a0798b commit 928bb32

File tree

15 files changed

+3646
-3
lines changed

15 files changed

+3646
-3
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
##### Features
2222

23+
- [`cbc4d3f`](https://github.com/stdlib-js/stdlib/commit/cbc4d3f7514b7213cad4f9d2ca5d916e13eeffa5) - add `reject` to namespace
2324
- [`831de1b`](https://github.com/stdlib-js/stdlib/commit/831de1b4ba21cda245c073a5412bf1a2e9d7598d) - add `map` and `filter` to namespace
2425
- [`8b1548f`](https://github.com/stdlib-js/stdlib/commit/8b1548fb45c1ff131f5edac20cb984344a2d28ec) - update namespace TypeScript declarations [(#3190)](https://github.com/stdlib-js/stdlib/pull/3190)
2526

@@ -235,6 +236,28 @@
235236

236237
<!-- /.package -->
237238

239+
<section class="package" id="ndarray-reject-unreleased">
240+
241+
#### [@stdlib/ndarray/reject](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/reject)
242+
243+
<details>
244+
245+
<section class="features">
246+
247+
##### Features
248+
249+
- [`43ccbfb`](https://github.com/stdlib-js/stdlib/commit/43ccbfbf9cd0ffcdd92fbe6ae0cc60db4f46ea6e) - add `ndarray/reject`
250+
251+
</section>
252+
253+
<!-- /.features -->
254+
255+
</details>
256+
257+
</section>
258+
259+
<!-- /.package -->
260+
238261
</section>
239262

240263
<!-- /.packages -->
@@ -271,6 +294,10 @@ A total of 3 people contributed to this release. Thank you to the following cont
271294

272295
<details>
273296

297+
- [`cbc4d3f`](https://github.com/stdlib-js/stdlib/commit/cbc4d3f7514b7213cad4f9d2ca5d916e13eeffa5) - **feat:** add `reject` to namespace _(by Athan Reines)_
298+
- [`43ccbfb`](https://github.com/stdlib-js/stdlib/commit/43ccbfbf9cd0ffcdd92fbe6ae0cc60db4f46ea6e) - **feat:** add `ndarray/reject` _(by Athan Reines)_
299+
- [`1cc3e09`](https://github.com/stdlib-js/stdlib/commit/1cc3e095080947f8fdd61ea2217f9b3031b9f93b) - **docs:** fix annotation _(by Athan Reines)_
300+
- [`7efc6f3`](https://github.com/stdlib-js/stdlib/commit/7efc6f3c8f899974f7d11cb9e06f65f90d5caaa9) - **bench:** fix symbol name _(by Athan Reines)_
274301
- [`17430f4`](https://github.com/stdlib-js/stdlib/commit/17430f4a7f15da00c9288b2b4d0577b6b7f8007f) - **docs:** add note _(by Athan Reines)_
275302
- [`354a147`](https://github.com/stdlib-js/stdlib/commit/354a1472bd69ab26c020aa7ba1df043c88e985b2) - **docs:** add note _(by Athan Reines)_
276303
- [`80542fd`](https://github.com/stdlib-js/stdlib/commit/80542fd459075dc2c49f6e529a21bd661129899e) - **docs:** remove note _(by Athan Reines)_

filter/benchmark/benchmark.2d.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
3030
var shape2strides = require( './../../base/shape2strides' );
3131
var ndarray = require( './../../ctor' );
3232
var pkg = require( './../package.json' ).name;
33-
var map = require( './../lib' );
33+
var filter = require( './../lib' );
3434

3535

3636
// VARIABLES //
@@ -94,7 +94,7 @@ function createBenchmark( len, shape, xtype, ytype, order ) {
9494

9595
b.tic();
9696
for ( i = 0; i < b.iterations; i++ ) {
97-
y = map( x, opts, predicate );
97+
y = filter( x, opts, predicate );
9898
if ( isnan( y.data[ i%y.length ] ) ) {
9999
b.fail( 'should not return NaN' );
100100
}

filter/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ var format = require( '@stdlib/string/format' );
4444
* @param {ndarray} x - input ndarray
4545
* @param {Options} [options] - function options
4646
* @param {string} [options.dtype] - output array data type
47-
* @param {boolean} [options.order='row-major'] - index iteration order
47+
* @param {boolean} [options.order] - index iteration order
4848
* @param {Callback} predicate - predicate function
4949
* @param {*} [thisArg] - predicate execution context
5050
* @throws {TypeError} first argument must be an ndarray-like object

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ setReadOnly( ns, 'outputDataTypePolicies', require( './../output-dtype-policies'
369369
*/
370370
setReadOnly( ns, 'promotionRules', require( './../promotion-rules' ) );
371371

372+
/**
373+
* @name reject
374+
* @memberof ns
375+
* @readonly
376+
* @type {Function}
377+
* @see {@link module:@stdlib/ndarray/reject}
378+
*/
379+
setReadOnly( ns, 'reject', require( './../reject' ) );
380+
372381
/**
373382
* @name safeCasts
374383
* @memberof ns

reject/README.md

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# reject
22+
23+
> Return a shallow copy of an [ndarray][@stdlib/ndarray/ctor] containing only those elements which fail a test implemented by a predicate function.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var reject = require( '@stdlib/ndarray/reject' );
37+
```
38+
39+
#### reject( x\[, options], predicate\[, thisArg] )
40+
41+
Returns a shallow copy of an [ndarray][@stdlib/ndarray/ctor] containing only those elements which fail a test implemented by a `predicate` function.
42+
43+
<!-- eslint-disable max-len -->
44+
45+
```javascript
46+
var Float64Array = require( '@stdlib/array/float64' );
47+
var ndarray = require( '@stdlib/ndarray/ctor' );
48+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
49+
50+
function predicate( z ) {
51+
return z <= 6.0;
52+
}
53+
54+
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 ] );
55+
var shape = [ 2, 3 ];
56+
var strides = [ 6, 1 ];
57+
var offset = 1;
58+
59+
var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
60+
// returns <ndarray>
61+
62+
var y = reject( x, predicate );
63+
// returns <ndarray>
64+
65+
var arr = ndarray2array( y );
66+
// returns [ 8.0, 9.0, 10.0 ]
67+
```
68+
69+
The function accepts the following arguments:
70+
71+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
72+
- **options**: function options.
73+
- **predicate**: predicate function.
74+
- **thisArg**: predicate function execution context.
75+
76+
The function accepts the following options:
77+
78+
- **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].
79+
- **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'`.
80+
81+
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.
82+
83+
<!-- eslint-disable max-len -->
84+
85+
```javascript
86+
var Float64Array = require( '@stdlib/array/float64' );
87+
var ndarray = require( '@stdlib/ndarray/ctor' );
88+
var dtype = require( '@stdlib/ndarray/dtype' );
89+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
90+
91+
function predicate( z ) {
92+
return z <= 6.0;
93+
}
94+
95+
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 ] );
96+
var shape = [ 2, 3 ];
97+
var strides = [ 6, 1 ];
98+
var offset = 1;
99+
100+
var x = ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
101+
// returns <ndarray>
102+
103+
var opts = {
104+
'dtype': 'float32'
105+
};
106+
var y = reject( x, opts, predicate );
107+
// returns <ndarray>
108+
109+
var dt = dtype( y );
110+
// returns 'float32'
111+
112+
var arr = ndarray2array( y );
113+
// returns [ 8.0, 9.0, 10.0 ]
114+
```
115+
116+
The `predicate` function is provided the following arguments:
117+
118+
- **value**: current array element.
119+
- **indices**: current array element indices.
120+
- **arr**: the input [ndarray][@stdlib/ndarray/ctor].
121+
122+
</section>
123+
124+
<!-- /.usage -->
125+
126+
<section class="notes">
127+
128+
## Notes
129+
130+
- 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.
131+
- The function **always** returns a one-dimensional [ndarray][@stdlib/ndarray/ctor].
132+
133+
</section>
134+
135+
<!-- /.notes -->
136+
137+
<section class="examples">
138+
139+
## Examples
140+
141+
<!-- eslint no-undef: "error" -->
142+
143+
```javascript
144+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
145+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
146+
var naryFunction = require( '@stdlib/utils/nary-function' );
147+
var array = require( '@stdlib/ndarray/array' );
148+
var isPositive = require( '@stdlib/assert/is-positive-number' ).isPrimitive;
149+
var reject = require( '@stdlib/ndarray/reject' );
150+
151+
var buffer = discreteUniform( 10, -100, 100, {
152+
'dtype': 'generic'
153+
});
154+
var x = array( buffer, {
155+
'shape': [ 5, 2 ],
156+
'dtype': 'generic'
157+
});
158+
console.log( ndarray2array( x ) );
159+
160+
var y = reject( x, naryFunction( isPositive, 1 ) );
161+
console.log( ndarray2array( y ) );
162+
```
163+
164+
</section>
165+
166+
<!-- /.examples -->
167+
168+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
169+
170+
<section class="related">
171+
172+
</section>
173+
174+
<!-- /.related -->
175+
176+
<section class="links">
177+
178+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
179+
180+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
181+
182+
[@stdlib/ndarray/orders]: https://github.com/stdlib-js/ndarray/tree/main/orders
183+
184+
<!-- <related-links> -->
185+
186+
<!-- </related-links> -->
187+
188+
</section>
189+
190+
<!-- /.links -->

0 commit comments

Comments
 (0)