Skip to content

Commit 471ca31

Browse files
committed
feat: add 7d 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 44f28ae commit 471ca31

File tree

4 files changed

+908
-0
lines changed

4 files changed

+908
-0
lines changed
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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+
/* eslint-disable max-depth */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
26+
var zeroTo = require( '@stdlib/array/base/zero-to' );
27+
var reverse = require( '@stdlib/array/base/reverse' );
28+
var take = require( '@stdlib/array/base/take-indexed' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Tests whether every element in an ndarray is truthy according to a callback function.
35+
*
36+
* @private
37+
* @param {Object} x - object containing ndarray meta data
38+
* @param {ndarrayLike} x.ref - reference to the original ndarray-like object
39+
* @param {string} x.dtype - data type
40+
* @param {Collection} x.data - data buffer
41+
* @param {NonNegativeIntegerArray} x.shape - dimensions
42+
* @param {IntegerArray} x.strides - stride lengths
43+
* @param {NonNegativeInteger} x.offset - index offset
44+
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
45+
* @param {Function} clbk - callback function
46+
* @param {*} thisArg - callback execution context
47+
* @returns {boolean} result
48+
*
49+
* @example
50+
* var Float64Array = require( '@stdlib/array/float64' );
51+
*
52+
* function clbk( value ) {
53+
* return value > 0.0;
54+
* }
55+
*
56+
* // Create a data buffer:
57+
* 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 ] );
58+
*
59+
* // Define the shape of the input array:
60+
* var shape = [ 1, 1, 1, 1, 3, 1, 2 ];
61+
*
62+
* // Define the array strides:
63+
* var sx = [ 12, 12, 12, 12, 4, 4, 1 ];
64+
*
65+
* // Define the index offset:
66+
* var ox = 1;
67+
*
68+
* // Create the input ndarray-like object:
69+
* var x = {
70+
* 'ref': null,
71+
* 'dtype': 'float64',
72+
* 'data': xbuf,
73+
* 'shape': shape,
74+
* 'strides': sx,
75+
* 'offset': ox,
76+
* 'order': 'row-major'
77+
* };
78+
*
79+
* // Test elements:
80+
* var out = every7d( x, clbk );
81+
* // returns true
82+
*/
83+
function every7d( x, clbk, thisArg ) {
84+
var xbuf;
85+
var idx;
86+
var dx0;
87+
var dx1;
88+
var dx2;
89+
var dx3;
90+
var dx4;
91+
var dx5;
92+
var dx6;
93+
var sh;
94+
var S0;
95+
var S1;
96+
var S2;
97+
var S3;
98+
var S4;
99+
var S5;
100+
var S6;
101+
var sx;
102+
var ix;
103+
var i0;
104+
var i1;
105+
var i2;
106+
var i3;
107+
var i4;
108+
var i5;
109+
var i6;
110+
111+
// Note on variable naming convention: S#, dx#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop...
112+
113+
// Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments...
114+
sh = x.shape;
115+
sx = x.strides;
116+
idx = zeroTo( sh.length );
117+
if ( isRowMajor( x.order ) ) {
118+
// For row-major ndarrays, the last dimensions have the fastest changing indices...
119+
S0 = sh[ 6 ];
120+
S1 = sh[ 5 ];
121+
S2 = sh[ 4 ];
122+
S3 = sh[ 3 ];
123+
S4 = sh[ 2 ];
124+
S5 = sh[ 1 ];
125+
S6 = sh[ 0 ];
126+
dx0 = sx[ 6 ]; // offset increment for innermost loop
127+
dx1 = sx[ 5 ] - ( S0*sx[6] );
128+
dx2 = sx[ 4 ] - ( S1*sx[5] );
129+
dx3 = sx[ 3 ] - ( S2*sx[4] );
130+
dx4 = sx[ 2 ] - ( S3*sx[3] );
131+
dx5 = sx[ 1 ] - ( S4*sx[2] );
132+
dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop
133+
} else { // order === 'column-major'
134+
// For column-major ndarrays, the first dimensions have the fastest changing indices...
135+
S0 = sh[ 0 ];
136+
S1 = sh[ 1 ];
137+
S2 = sh[ 2 ];
138+
S3 = sh[ 3 ];
139+
S4 = sh[ 4 ];
140+
S5 = sh[ 5 ];
141+
S6 = sh[ 6 ];
142+
dx0 = sx[ 0 ]; // offset increment for innermost loop
143+
dx1 = sx[ 1 ] - ( S0*sx[0] );
144+
dx2 = sx[ 2 ] - ( S1*sx[1] );
145+
dx3 = sx[ 3 ] - ( S2*sx[2] );
146+
dx4 = sx[ 4 ] - ( S3*sx[3] );
147+
dx5 = sx[ 5 ] - ( S4*sx[4] );
148+
dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop
149+
idx = reverse( idx );
150+
}
151+
// Set a pointer to the first indexed element:
152+
ix = x.offset;
153+
154+
// Cache a reference to the input ndarray buffer:
155+
xbuf = x.data;
156+
157+
// Iterate over the ndarray dimensions...
158+
for ( i6 = 0; i6 < S6; i6++ ) {
159+
for ( i5 = 0; i5 < S5; i5++ ) {
160+
for ( i4 = 0; i4 < S4; i4++ ) {
161+
for ( i3 = 0; i3 < S3; i3++ ) {
162+
for ( i2 = 0; i2 < S2; i2++ ) {
163+
for ( i1 = 0; i1 < S1; i1++ ) {
164+
for ( i0 = 0; i0 < S0; i0++ ) {
165+
if ( !clbk.call( thisArg, xbuf[ ix ], take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len
166+
return false;
167+
}
168+
ix += dx0;
169+
}
170+
ix += dx1;
171+
}
172+
ix += dx2;
173+
}
174+
ix += dx3;
175+
}
176+
ix += dx4;
177+
}
178+
ix += dx5;
179+
}
180+
ix += dx6;
181+
}
182+
return true;
183+
}
184+
185+
186+
// EXPORTS //
187+
188+
module.exports = every7d;
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
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+
/* eslint-disable max-depth */
20+
21+
'use strict';
22+
23+
// MODULES //
24+
25+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
26+
var zeroTo = require( '@stdlib/array/base/zero-to' );
27+
var reverse = require( '@stdlib/array/base/reverse' );
28+
var take = require( '@stdlib/array/base/take-indexed' );
29+
30+
31+
// MAIN //
32+
33+
/**
34+
* Tests whether every element in an ndarray is truthy according to a callback function.
35+
*
36+
* @private
37+
* @param {Object} x - object containing ndarray meta data
38+
* @param {ndarrayLike} x.ref - reference to the original ndarray-like object
39+
* @param {string} x.dtype - data type
40+
* @param {Collection} x.data - data buffer
41+
* @param {NonNegativeIntegerArray} x.shape - dimensions
42+
* @param {IntegerArray} x.strides - stride lengths
43+
* @param {NonNegativeInteger} x.offset - index offset
44+
* @param {string} x.order - specifies whether `x` is row-major (C-style) or column-major (Fortran-style)
45+
* @param {Array<Function>} x.accessors - data buffer accessors
46+
* @param {Function} clbk - callback function
47+
* @param {*} thisArg - callback execution context
48+
* @returns {boolean} result
49+
*
50+
* @example
51+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
52+
* var accessors = require( '@stdlib/array/base/accessors' );
53+
*
54+
* function clbk( value ) {
55+
* return value > 0.0;
56+
* }
57+
*
58+
* // Create a data buffer:
59+
* var xbuf = toAccessorArray( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
60+
*
61+
* // Define the shape of the input array:
62+
* var shape = [ 1, 1, 1, 1, 1, 2, 2 ];
63+
*
64+
* // Define the array strides:
65+
* var sx = [ 4, 4, 4, 4, 4, 2, 1 ];
66+
*
67+
* // Define the index offset:
68+
* var ox = 0;
69+
*
70+
* // Create the input ndarray-like object:
71+
* var x = {
72+
* 'ref': null,
73+
* 'dtype': 'generic',
74+
* 'data': xbuf,
75+
* 'shape': shape,
76+
* 'strides': sx,
77+
* 'offset': ox,
78+
* 'order': 'row-major',
79+
* 'accessors': accessors( xbuf ).accessors
80+
* };
81+
*
82+
* // Test elements:
83+
* var out = every7d( x, clbk );
84+
* // returns true
85+
*/
86+
function every7d( x, clbk, thisArg ) {
87+
var xbuf;
88+
var idx;
89+
var get;
90+
var dx0;
91+
var dx1;
92+
var dx2;
93+
var dx3;
94+
var dx4;
95+
var dx5;
96+
var dx6;
97+
var sh;
98+
var S0;
99+
var S1;
100+
var S2;
101+
var S3;
102+
var S4;
103+
var S5;
104+
var S6;
105+
var sx;
106+
var ix;
107+
var i0;
108+
var i1;
109+
var i2;
110+
var i3;
111+
var i4;
112+
var i5;
113+
var i6;
114+
115+
// Note on variable naming convention: S#, dx#, dy#, i# where # corresponds to the loop number, with `0` being the innermost loop...
116+
117+
// Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments...
118+
sh = x.shape;
119+
sx = x.strides;
120+
idx = zeroTo( sh.length );
121+
if ( isRowMajor( x.order ) ) {
122+
// For row-major ndarrays, the last dimensions have the fastest changing indices...
123+
S0 = sh[ 6 ];
124+
S1 = sh[ 5 ];
125+
S2 = sh[ 4 ];
126+
S3 = sh[ 3 ];
127+
S4 = sh[ 2 ];
128+
S5 = sh[ 1 ];
129+
S6 = sh[ 0 ];
130+
dx0 = sx[ 6 ]; // offset increment for innermost loop
131+
dx1 = sx[ 5 ] - ( S0*sx[6] );
132+
dx2 = sx[ 4 ] - ( S1*sx[5] );
133+
dx3 = sx[ 3 ] - ( S2*sx[4] );
134+
dx4 = sx[ 2 ] - ( S3*sx[3] );
135+
dx5 = sx[ 1 ] - ( S4*sx[2] );
136+
dx6 = sx[ 0 ] - ( S5*sx[1] ); // offset increment for outermost loop
137+
} else { // order === 'column-major'
138+
// For column-major ndarrays, the first dimensions have the fastest changing indices...
139+
S0 = sh[ 0 ];
140+
S1 = sh[ 1 ];
141+
S2 = sh[ 2 ];
142+
S3 = sh[ 3 ];
143+
S4 = sh[ 4 ];
144+
S5 = sh[ 5 ];
145+
S6 = sh[ 6 ];
146+
dx0 = sx[ 0 ]; // offset increment for innermost loop
147+
dx1 = sx[ 1 ] - ( S0*sx[0] );
148+
dx2 = sx[ 2 ] - ( S1*sx[1] );
149+
dx3 = sx[ 3 ] - ( S2*sx[2] );
150+
dx4 = sx[ 4 ] - ( S3*sx[3] );
151+
dx5 = sx[ 5 ] - ( S4*sx[4] );
152+
dx6 = sx[ 6 ] - ( S5*sx[5] ); // offset increment for outermost loop
153+
idx = reverse( idx );
154+
}
155+
// Set a pointer to the first indexed element:
156+
ix = x.offset;
157+
158+
// Cache a reference to the input ndarray buffer:
159+
xbuf = x.data;
160+
161+
// Cache accessor:
162+
get = x.accessors[ 0 ];
163+
164+
// Iterate over the ndarray dimensions...
165+
for ( i6 = 0; i6 < S6; i6++ ) {
166+
for ( i5 = 0; i5 < S5; i5++ ) {
167+
for ( i4 = 0; i4 < S4; i4++ ) {
168+
for ( i3 = 0; i3 < S3; i3++ ) {
169+
for ( i2 = 0; i2 < S2; i2++ ) {
170+
for ( i1 = 0; i1 < S1; i1++ ) {
171+
for ( i0 = 0; i0 < S0; i0++ ) {
172+
if ( !clbk.call( thisArg, get( xbuf, ix ), take( [ i6, i5, i4, i3, i2, i1, i0 ], idx ), x.ref ) ) { // eslint-disable-line max-len
173+
return false;
174+
}
175+
ix += dx0;
176+
}
177+
ix += dx1;
178+
}
179+
ix += dx2;
180+
}
181+
ix += dx3;
182+
}
183+
ix += dx4;
184+
}
185+
ix += dx5;
186+
}
187+
ix += dx6;
188+
}
189+
return true;
190+
}
191+
192+
193+
// EXPORTS //
194+
195+
module.exports = every7d;

0 commit comments

Comments
 (0)