Skip to content

Commit 1392a91

Browse files
committed
feat: add 0d 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: 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: na - 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 d2564c7 commit 1392a91

File tree

3 files changed

+239
-0
lines changed

3 files changed

+239
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
// MAIN //
22+
23+
/**
24+
* Tests whether an ndarray contains a specified value.
25+
*
26+
* @private
27+
* @param {Object} x - object containing ndarray meta data
28+
* @param {string} x.dtype - data type
29+
* @param {Collection} x.data - data buffer
30+
* @param {NonNegativeIntegerArray} x.shape - dimensions
31+
* @param {IntegerArray} x.strides - stride lengths
32+
* @param {NonNegativeInteger} x.offset - index offset
33+
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
34+
* @param {*} value - search element
35+
* @returns {boolean} result
36+
*
37+
* @example
38+
* var Float64Array = require( '@stdlib/array/float64' );
39+
*
40+
* // Create a data buffer:
41+
* var xbuf = new Float64Array( [ 1.0, 2.0 ] );
42+
*
43+
* // Define the shape of the input array:
44+
* var shape = [];
45+
*
46+
* // Define the array strides:
47+
* var sx = [ 0 ];
48+
*
49+
* // Define the index offset:
50+
* var ox = 1;
51+
*
52+
* // Create the input ndarray-like object:
53+
* var x = {
54+
* 'dtype': 'float64',
55+
* 'data': xbuf,
56+
* 'shape': shape,
57+
* 'strides': sx,
58+
* 'offset': ox,
59+
* 'order': 'row-major'
60+
* };
61+
*
62+
* // Perform reduction:
63+
* var out = includes0d( x, 2.0 );
64+
* // returns true
65+
*
66+
* out = includes0d( x, 100.0 );
67+
* // returns false
68+
*/
69+
function includes0d( x, value ) {
70+
return ( x.data[ x.offset ] === value );
71+
}
72+
73+
74+
// EXPORTS //
75+
76+
module.exports = includes0d;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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+
// MAIN //
22+
23+
/**
24+
* Tests whether an ndarray contains a specified value.
25+
*
26+
* @private
27+
* @param {Object} x - object containing ndarray meta data
28+
* @param {string} x.dtype - data type
29+
* @param {Collection} x.data - data buffer
30+
* @param {NonNegativeIntegerArray} x.shape - dimensions
31+
* @param {IntegerArray} x.strides - stride lengths
32+
* @param {NonNegativeInteger} x.offset - index offset
33+
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
34+
* @param {Array<Function>} x.accessors - data buffer accessors
35+
* @param {*} value - search element
36+
* @returns {boolean} result
37+
*
38+
* @example
39+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
40+
* var accessors = require( '@stdlib/array/base/accessors' );
41+
*
42+
* // Create a data buffer:
43+
* var xbuf = toAccessorArray( [ 1.0, 2.0 ] );
44+
*
45+
* // Define the shape of the input array:
46+
* var shape = [];
47+
*
48+
* // Define the array strides:
49+
* var sx = [ 0 ];
50+
*
51+
* // Define the index offset:
52+
* var ox = 1;
53+
*
54+
* // Create the input ndarray-like object:
55+
* var x = {
56+
* 'dtype': 'generic',
57+
* 'data': xbuf,
58+
* 'shape': shape,
59+
* 'strides': sx,
60+
* 'offset': ox,
61+
* 'order': 'row-major',
62+
* 'accessors': accessors( xbuf ).accessors
63+
* };
64+
*
65+
* // Perform reduction:
66+
* var out = includes0d( x, 2.0 );
67+
* // returns true
68+
*
69+
* out = includes0d( x, 100.0 );
70+
* // returns false
71+
*/
72+
function includes0d( x, value ) {
73+
return ( x.accessors[ 0 ]( x.data, x.offset ) === value );
74+
}
75+
76+
77+
// EXPORTS //
78+
79+
module.exports = includes0d;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
// MAIN //
22+
23+
/**
24+
* Tests whether a reinterpreted complex number ndarray contains a specified value.
25+
*
26+
* @private
27+
* @param {Object} x - object containing ndarray meta data
28+
* @param {string} x.dtype - data type
29+
* @param {Collection} x.data - data buffer
30+
* @param {NonNegativeIntegerArray} x.shape - dimensions
31+
* @param {IntegerArray} x.strides - stride lengths
32+
* @param {NonNegativeInteger} x.offset - index offset
33+
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
34+
* @param {ComplexLike} value - search element
35+
* @returns {boolean} result
36+
*
37+
* @example
38+
* var Float64Array = require( '@stdlib/array/float64' );
39+
*
40+
* // Create a data buffer:
41+
* var xbuf = new Float64Array( [ 1.0, 2.0 ] );
42+
*
43+
* // Define the shape of the input array:
44+
* var shape = [];
45+
*
46+
* // Define the array strides:
47+
* var sx = [ 0 ];
48+
*
49+
* // Define the index offset:
50+
* var ox = 0;
51+
*
52+
* // Create the input ndarray-like object:
53+
* var x = {
54+
* 'dtype': 'complex128',
55+
* 'data': xbuf,
56+
* 'shape': shape,
57+
* 'strides': sx,
58+
* 'offset': ox,
59+
* 'order': 'row-major'
60+
* };
61+
*
62+
* // Perform reduction:
63+
* var v = {
64+
* 're': 1.0,
65+
* 'im': 2.0
66+
* };
67+
* var out = includes0d( x, v );
68+
* // returns true
69+
*
70+
* v = {
71+
* 're': -3.0,
72+
* 'im': -4.0
73+
* };
74+
* out = includes0d( x, v );
75+
* // returns false
76+
*/
77+
function includes0d( x, value ) {
78+
return ( x.data[ x.offset ] === value.re && x.data[ x.offset+1 ] === value.im ); // eslint-disable-line max-len
79+
}
80+
81+
82+
// EXPORTS //
83+
84+
module.exports = includes0d;

0 commit comments

Comments
 (0)