Skip to content

Commit 8190372

Browse files
committed
feat: add 4d kernels
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent ed3693f commit 8190372

File tree

7 files changed

+984
-7
lines changed

7 files changed

+984
-7
lines changed

lib/node_modules/@stdlib/ndarray/base/some-by/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ limitations under the License.
3636
var someBy = require( '@stdlib/ndarray/base/some-by' );
3737
```
3838

39-
#### someBy( arrays, clbk\[, thisArg ] )
39+
#### someBy( arrays, predicate\[, thisArg ] )
4040

4141
Tests whether at least `n` elements in an ndarray pass a test implemented by a predicate function.
4242

@@ -46,7 +46,7 @@ Tests whether at least `n` elements in an ndarray pass a test implemented by a p
4646
var Float64Array = require( '@stdlib/array/float64' );
4747
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
4848

49-
function clbk( value ) {
49+
function predicate( value ) {
5050
return value > 0.0;
5151
}
5252

@@ -74,7 +74,7 @@ var x = {
7474

7575
var n = scalar2ndarray( 3.0, 'generic', 'row-major' );
7676

77-
var out = someBy( [ x, n ], clbk );
77+
var out = someBy( [ x, n ], predicate );
7878
// returns true
7979
```
8080

@@ -107,7 +107,7 @@ To set the predicate function execution context, provide a `thisArg`.
107107
var Float64Array = require( '@stdlib/array/float64' );
108108
var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
109109

110-
function clbk( value ) {
110+
function predicate( value ) {
111111
this.count += 1;
112112
return value > 0.0;
113113
}
@@ -140,7 +140,7 @@ var ctx = {
140140
'count': 0
141141
};
142142

143-
var out = someBy( [ x, n ], clbk, ctx );
143+
var out = someBy( [ x, n ], predicate, ctx );
144144
// returns true
145145

146146
var count = ctx.count;
@@ -173,7 +173,7 @@ var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
173173
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
174174
var someBy = require( '@stdlib/ndarray/base/some-by' );
175175

176-
function clbk( value ) {
176+
function predicate( value ) {
177177
return value > 0;
178178
}
179179

@@ -193,7 +193,7 @@ var n = scalar2ndarray( 5.0, {
193193
'dtype': 'generic'
194194
});
195195

196-
var out = someBy( [ x, n ], clbk );
196+
var out = someBy( [ x, n ], predicate );
197197
console.log( out );
198198
```
199199

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pow = require( '@stdlib/math/base/special/pow' );
26+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
27+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
28+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
29+
var pkg = require( './../package.json' ).name;
30+
var someBy = require( './../lib' );
31+
32+
33+
// VARIABLES //
34+
35+
var types = [ 'float64' ];
36+
var order = 'row-major';
37+
38+
39+
// FUNCTIONS //
40+
41+
/**
42+
* Predicate function.
43+
*
44+
* @param {*} value - ndarray element
45+
* @returns {boolean} result
46+
*/
47+
function clbk( value ) {
48+
return value > 0.0;
49+
}
50+
51+
/**
52+
* Creates a benchmark function.
53+
*
54+
* @private
55+
* @param {PositiveInteger} len - ndarray length
56+
* @param {NonNegativeIntegerArray} shape - ndarray shape
57+
* @param {string} xtype - ndarray data type
58+
* @returns {Function} benchmark function
59+
*/
60+
function createBenchmark( len, shape, xtype ) {
61+
var x;
62+
var n;
63+
64+
x = discreteUniform( len, 1, 100 );
65+
x = {
66+
'dtype': xtype,
67+
'data': x,
68+
'shape': shape,
69+
'strides': shape2strides( shape, order ),
70+
'offset': 0,
71+
'order': order
72+
};
73+
n = scalar2ndarray( 5.0, {
74+
'dtype': 'generic'
75+
});
76+
return benchmark;
77+
78+
/**
79+
* Benchmark function.
80+
*
81+
* @private
82+
* @param {Benchmark} b - benchmark instance
83+
*/
84+
function benchmark( b ) {
85+
var out;
86+
var i;
87+
88+
b.tic();
89+
for ( i = 0; i < b.iterations; i++ ) {
90+
out = someBy( [ x, n ], clbk );
91+
if ( typeof out !== 'boolean' ) {
92+
b.fail( 'should return a boolean' );
93+
}
94+
}
95+
b.toc();
96+
if ( !isBoolean( out ) ) {
97+
b.fail( 'should return a boolean' );
98+
}
99+
b.pass( 'benchmark finished' );
100+
b.end();
101+
}
102+
}
103+
104+
105+
// MAIN //
106+
107+
/**
108+
* Main execution sequence.
109+
*
110+
* @private
111+
*/
112+
function main() {
113+
var len;
114+
var min;
115+
var max;
116+
var sh;
117+
var t1;
118+
var f;
119+
var i;
120+
var j;
121+
122+
min = 1; // 10^min
123+
max = 6; // 10^max
124+
125+
for ( j = 0; j < types.length; j++ ) {
126+
t1 = types[ j ];
127+
for ( i = min; i <= max; i++ ) {
128+
len = pow( 10, i );
129+
130+
sh = [ len ];
131+
f = createBenchmark( len, sh, t1 );
132+
bench( pkg+':ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],xorder='+order+',xtype='+t1, f );
133+
}
134+
}
135+
}
136+
137+
main();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
{{alias}}( arrays, predicate[, thisArg] )
3+
Tests whether at least `n` elements in an ndarray pass a test implemented by
4+
a predicate function.
5+
6+
A provided "ndarray" should be an `object` with the following properties:
7+
8+
- dtype: data type.
9+
- data: data buffer.
10+
- shape: dimensions.
11+
- strides: stride lengths.
12+
- offset: index offset.
13+
- order: specifies whether an ndarray is row-major (C-style) or column-major
14+
(Fortran-style).
15+
16+
The predicate function is provided the following arguments:
17+
18+
- value: current array element.
19+
- indices: current array element indices.
20+
- arr: the input ndarray.
21+
22+
Parameters
23+
----------
24+
arrays: ArrayLikeObject<ndarray>
25+
Array-like object containing an input ndarray and a 0-dimensional
26+
ndarray containing number of elements.
27+
28+
predicate: Function
29+
Predicate function.
30+
31+
thisArg: any (optional)
32+
Predicate function execution context.
33+
34+
Returns
35+
-------
36+
out: boolean
37+
Boolean indicating whether at least `n` elements in an ndarray pass a
38+
test implemented by a predicate function.
39+
40+
Examples
41+
--------
42+
// Define ndarray data and meta data...
43+
> var xbuf = new {{alias:@stdlib/array/float64}}( [ 1.0, 1.0, 0.0, 1.0 ] );
44+
> var dt = 'float64';
45+
> var sh = [ 2, 2 ];
46+
> var sx = [ 2, 1 ];
47+
> var ox = 0;
48+
> var ord = 'row-major';
49+
50+
// Define a callback...
51+
> function clbk( v ) { return v > 0.0; };
52+
53+
// Using an ndarray...
54+
> var x = {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, sx, ox, ord );
55+
> var n = {{alias:@stdlib/ndarray/from-scalar}}( 3, { 'dtype': 'generic' });
56+
> {{alias}}( [ x, n ], clbk )
57+
true
58+
59+
// Using a minimal ndarray-like object...
60+
> xbuf = new {{alias:@stdlib/array/float64}}( [ -1.0, -1.0, -1.0, -1.0 ] );
61+
> x = {
62+
... 'dtype': dt,
63+
... 'data': xbuf,
64+
... 'shape': sh,
65+
... 'strides': sx,
66+
... 'offset': ox,
67+
... 'order': ord
68+
... };
69+
> {{alias}}( [ x, n ], clbk )
70+
false
71+
72+
See Also
73+
--------
74+

0 commit comments

Comments
 (0)