Skip to content

Commit e9a30f2

Browse files
committed
feat: add ts defs
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 8190372 commit e9a30f2

File tree

4 files changed

+218
-3
lines changed

4 files changed

+218
-3
lines changed

lib/node_modules/@stdlib/ndarray/base/some-by/benchmark/benchmark.1d_rowmajor.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ function createBenchmark( len, shape, xtype ) {
7171
'order': order
7272
};
7373
n = scalar2ndarray( 5.0, {
74-
'dtype': 'generic'
74+
'dtype': 'generic',
75+
'order': order
7576
});
7677
return benchmark;
7778

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ArrayLike } from '@stdlib/types/array';
24+
import { typedndarray } from '@stdlib/types/ndarray';
25+
26+
/**
27+
* Returns a boolean indicating whether an element passes a test.
28+
*
29+
* @returns boolean indicating whether an ndarray element passes a test
30+
*/
31+
type Nullary<U> = ( this: U ) => boolean;
32+
33+
/**
34+
* Returns a boolean indicating whether an element passes a test.
35+
*
36+
* @param value - current array element
37+
* @returns boolean indicating whether an ndarray element passes a test
38+
*/
39+
type Unary<T, U> = ( this: U, value: T ) => boolean;
40+
41+
/**
42+
* Returns a boolean indicating whether an element passes a test.
43+
*
44+
* @param value - current array element
45+
* @param indices - current array element indices
46+
* @returns boolean indicating whether an ndarray element passes a test
47+
*/
48+
type Binary<T, U> = ( this: U, value: T, indices: Array<number> ) => boolean;
49+
50+
/**
51+
* Returns a boolean indicating whether an element passes a test.
52+
*
53+
* @param value - current array element
54+
* @param indices - current array element indices
55+
* @param arr - input array
56+
* @returns boolean indicating whether an ndarray element passes a test
57+
*/
58+
type Ternary<T, U> = ( this: U, value: T, indices: Array<number>, arr: typedndarray<T> ) => boolean;
59+
60+
/**
61+
* Returns a boolean indicating whether an element passes a test.
62+
*
63+
* @param value - current array element
64+
* @param indices - current array element indices
65+
* @param arr - input array
66+
* @returns boolean indicating whether an ndarray element passes a test
67+
*/
68+
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
69+
70+
/**
71+
* Tests whether at least `n` elements in an ndarray pass a test implemented by a predicate function.
72+
*
73+
* @param arrays - array-like object containing an input ndarray and a 0-dimensional ndarray containing the number of elements
74+
* @param predicate - predicate function
75+
* @param thisArg - predicate function execution context
76+
* @returns boolean indicating whether all elements pass a test
77+
*
78+
* @example
79+
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
80+
* var Float64Array = require( '@stdlib/array/float64' );
81+
*
82+
* function predicate( value ) {
83+
* return value > 0.0;
84+
* }
85+
*
86+
* // Create data buffers:
87+
* var xbuf = 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 ] );
88+
*
89+
* // Define the shape of the array:
90+
* var shape = [ 3, 1, 2 ];
91+
*
92+
* // Define the array strides:
93+
* var sx = [ 4, 4, 1 ];
94+
*
95+
* // Define the index offset:
96+
* var ox = 1;
97+
*
98+
* // Create the input ndarray:
99+
* var x = ndarray( 'float64', xbuf, shape, sx, ox, 'row-major' );
100+
* var n = scalar2ndarray( 3.0, { 'dtype': 'generic' } );
101+
*
102+
* // Test elements:
103+
* var out = someBy( [ x, n ], predicate );
104+
* // returns true
105+
*/
106+
declare function someBy<T = unknown, U = unknown>( arrays: ArrayLike<typedndarray<T>>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): boolean;
107+
108+
109+
// EXPORTS //
110+
111+
export = someBy;
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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+
/// <reference types="@stdlib/types"/>
20+
21+
import zeros = require( '@stdlib/ndarray/zeros' );
22+
import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
23+
import someBy = require( './index' );
24+
25+
/**
26+
* Predicate function.
27+
*
28+
* @param v - ndarray element
29+
* @returns result
30+
*/
31+
function clbk( v: any ): boolean {
32+
return v > 0.0;
33+
}
34+
35+
36+
// TESTS //
37+
38+
// The function returns a boolean...
39+
{
40+
const x = zeros( [ 2, 2 ] );
41+
const n = scalar2ndarray( 2, { 'dtype': 'generic' } );
42+
const arrays = [ x, n ];
43+
44+
someBy( arrays, clbk ); // $ExpectType boolean
45+
someBy( arrays, clbk, {} ); // $ExpectType boolean
46+
}
47+
48+
// The compiler throws an error if the function is provided a first argument which is not an array-like object containing ndarray-like objects...
49+
{
50+
someBy( 5, clbk ); // $ExpectError
51+
someBy( true, clbk ); // $ExpectError
52+
someBy( false, clbk ); // $ExpectError
53+
someBy( null, clbk ); // $ExpectError
54+
someBy( undefined, clbk ); // $ExpectError
55+
someBy( {}, clbk ); // $ExpectError
56+
someBy( [ 1 ], clbk ); // $ExpectError
57+
someBy( ( x: number ): number => x, clbk ); // $ExpectError
58+
59+
someBy( 5, clbk, {} ); // $ExpectError
60+
someBy( true, clbk, {} ); // $ExpectError
61+
someBy( false, clbk, {} ); // $ExpectError
62+
someBy( null, clbk, {} ); // $ExpectError
63+
someBy( undefined, clbk, {} ); // $ExpectError
64+
someBy( {}, clbk, {} ); // $ExpectError
65+
someBy( [ 1 ], clbk, {} ); // $ExpectError
66+
someBy( ( x: number ): number => x, clbk, {} ); // $ExpectError
67+
}
68+
69+
// The compiler throws an error if the function is provided a second argument which is not a callback function...
70+
{
71+
const x = zeros( [ 2, 2 ] );
72+
const n = scalar2ndarray( 2, { 'dtype': 'generic' } );
73+
const arrays = [ x, n ];
74+
75+
someBy( arrays, '10' ); // $ExpectError
76+
someBy( arrays, 5 ); // $ExpectError
77+
someBy( arrays, true ); // $ExpectError
78+
someBy( arrays, false ); // $ExpectError
79+
someBy( arrays, null ); // $ExpectError
80+
someBy( arrays, undefined ); // $ExpectError
81+
someBy( arrays, [] ); // $ExpectError
82+
someBy( arrays, {} ); // $ExpectError
83+
84+
someBy( arrays, '10', {} ); // $ExpectError
85+
someBy( arrays, 5, {} ); // $ExpectError
86+
someBy( arrays, true, {} ); // $ExpectError
87+
someBy( arrays, false, {} ); // $ExpectError
88+
someBy( arrays, null, {} ); // $ExpectError
89+
someBy( arrays, undefined, {} ); // $ExpectError
90+
someBy( arrays, [], {} ); // $ExpectError
91+
someBy( arrays, {}, {} ); // $ExpectError
92+
}
93+
94+
// The compiler throws an error if the function is provided an unsupported number of arguments...
95+
{
96+
const x = zeros( [ 2, 2 ] );
97+
const n = scalar2ndarray( 2, { 'dtype': 'generic' } );
98+
const arrays = [ x, n ];
99+
100+
someBy(); // $ExpectError
101+
someBy( arrays ); // $ExpectError
102+
someBy( arrays, clbk, {}, {} ); // $ExpectError
103+
}

lib/node_modules/@stdlib/ndarray/base/some-by/lib/main.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var MAX_DIMS = SOME.length - 1;
8686
* @returns {boolean} boolean indicating whether `n` elements pass a test
8787
*
8888
* @example
89-
* var scalar2ndarray = require( '@stdlib/ndarray/base/from-scalar' );
89+
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
9090
* var Float64Array = require( '@stdlib/array/float64' );
9191
*
9292
* function predicate( value ) {
@@ -116,7 +116,7 @@ var MAX_DIMS = SOME.length - 1;
116116
* 'order': 'row-major'
117117
* };
118118
*
119-
* var n = scalar2ndarray( 3.0, 'generic', 'row-major' );
119+
* var n = scalar2ndarray( 3.0, { 'dtype': 'generic' } );
120120
*
121121
* // Test elements:
122122
* var out = someBy( [ x, n ], predicate );

0 commit comments

Comments
 (0)