Skip to content

Commit 4b2a5de

Browse files
committed
feat: add implementation for ndarray/base/every
--- 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 843fd22 commit 4b2a5de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+11871
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 every element is truthy.
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+
* @returns {boolean} result
35+
*
36+
* @example
37+
* var Float64Array = require( '@stdlib/array/float64' );
38+
*
39+
* // Create a data buffer:
40+
* var xbuf = new Float64Array( [ 1.0, 2.0 ] );
41+
*
42+
* // Define the shape of the input array:
43+
* var shape = [];
44+
*
45+
* // Define the array strides:
46+
* var sx = [ 0 ];
47+
*
48+
* // Define the index offset:
49+
* var ox = 1;
50+
*
51+
* // Create the input ndarray-like object:
52+
* var x = {
53+
* 'dtype': 'float64',
54+
* 'data': xbuf,
55+
* 'shape': shape,
56+
* 'strides': sx,
57+
* 'offset': ox,
58+
* 'order': 'row-major'
59+
* };
60+
*
61+
* // Test elements:
62+
* var out = every0d( x );
63+
* // returns true
64+
*/
65+
function every0d( x ) {
66+
if ( x.data[ x.offset ] ) {
67+
return true;
68+
}
69+
return false;
70+
}
71+
72+
73+
// EXPORTS //
74+
75+
module.exports = every0d;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 every element is truthy.
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+
* @returns {boolean} result
36+
*
37+
* @example
38+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
39+
* var accessors = require( '@stdlib/array/base/accessors' );
40+
*
41+
* // Create a data buffer:
42+
* var xbuf = toAccessorArray( [ 1.0, 2.0 ] );
43+
*
44+
* // Define the shape of the input array:
45+
* var shape = [];
46+
*
47+
* // Define the array strides:
48+
* var sx = [ 0 ];
49+
*
50+
* // Define the index offset:
51+
* var ox = 1;
52+
*
53+
* // Create the input ndarray-like object:
54+
* var x = {
55+
* 'dtype': 'generic',
56+
* 'data': xbuf,
57+
* 'shape': shape,
58+
* 'strides': sx,
59+
* 'offset': ox,
60+
* 'order': 'row-major',
61+
* 'accessors': accessors( xbuf ).accessors
62+
* };
63+
*
64+
* // Test elements:
65+
* var out = every0d( x );
66+
* // returns true
67+
*/
68+
function every0d( x ) {
69+
if ( x.accessors[ 0 ]( x.data, x.offset ) ) {
70+
return true;
71+
}
72+
return false;
73+
}
74+
75+
76+
// EXPORTS //
77+
78+
module.exports = every0d;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 every element of a reinterpreted complex number ndarray is truthy.
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+
* @returns {boolean} result
35+
*
36+
* @example
37+
* var Float64Array = require( '@stdlib/array/float64' );
38+
*
39+
* // Create a data buffer:
40+
* var xbuf = new Float64Array( [ 1.0, 2.0 ] );
41+
*
42+
* // Define the shape of the input array:
43+
* var shape = [];
44+
*
45+
* // Define the array strides:
46+
* var sx = [ 0 ];
47+
*
48+
* // Define the index offset:
49+
* var ox = 0;
50+
*
51+
* // Create the input ndarray-like object:
52+
* var x = {
53+
* 'dtype': 'complex128',
54+
* 'data': xbuf,
55+
* 'shape': shape,
56+
* 'strides': sx,
57+
* 'offset': ox,
58+
* 'order': 'row-major'
59+
* };
60+
*
61+
* // Test elements:
62+
* var out = every0d( x );
63+
* // returns true
64+
*/
65+
function every0d( x ) {
66+
if ( x.data[ x.offset ] || x.data[ x.offset+1 ] ) {
67+
return true;
68+
}
69+
return false;
70+
}
71+
72+
73+
// EXPORTS //
74+
75+
module.exports = every0d;

0 commit comments

Comments
 (0)