Skip to content

Commit a7b4c7f

Browse files
committed
feat: add missing 3d 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 --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 57efa3d commit a7b4c7f

File tree

4 files changed

+649
-3
lines changed

4 files changed

+649
-3
lines changed

lib/node_modules/@stdlib/ndarray/base/unary-reduce-subarray/lib/3d.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ var offsets = require( './offsets.js' );
9494
* ];
9595
*
9696
* // Perform a reduction:
97-
* unary2d( base, [ x, y ], views, [ 12, 12, 4 ], {} );
97+
* unary3d( base, [ x, y ], views, [ 12, 12, 4 ], {} );
9898
*
9999
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
100100
* // returns [ [ [ true, false, true ] ] ]
101101
*/
102-
function unary2d( fcn, arrays, views, strides, opts ) {
102+
function unary3d( fcn, arrays, views, strides, opts ) {
103103
var ybuf;
104104
var dv0;
105105
var dv1;
@@ -175,4 +175,4 @@ function unary2d( fcn, arrays, views, strides, opts ) {
175175

176176
// EXPORTS //
177177

178-
module.exports = unary2d;
178+
module.exports = unary3d;
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
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 isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
24+
var incrementOffsets = require( './increment_offsets.js' );
25+
var setViewOffsets = require( './set_view_offsets.js' );
26+
var offsets = require( './offsets.js' );
27+
28+
29+
// MAIN //
30+
31+
/**
32+
* Performs a reduction over an input ndarray and assigns results to a provided output ndarray.
33+
*
34+
* @private
35+
* @param {Function} fcn - reduction function
36+
* @param {Array<Object>} arrays - ndarrays
37+
* @param {Array<Object>} views - initialized ndarray-like objects representing sub-array views
38+
* @param {IntegerArray} strides - loop dimension strides for the input ndarray
39+
* @param {Options} opts - function options
40+
* @returns {void}
41+
*
42+
* @example
43+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
44+
* var accessors = require( '@stdlib/array/base/accessors' );
45+
* var Float64Array = require( '@stdlib/array/float64' );
46+
* var filled = require( '@stdlib/array/base/filled' );
47+
* var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
48+
* var base = require( '@stdlib/ndarray/base/every' );
49+
*
50+
* // Create data buffers:
51+
* var xbuf = toAccessorArray( new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 0.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] ) );
52+
* var ybuf = toAccessorArray( filled( false, 3 ) );
53+
*
54+
* // Define the array shapes:
55+
* var xsh = [ 1, 1, 3, 2, 2 ];
56+
* var ysh = [ 1, 1, 3 ];
57+
*
58+
* // Define the array strides:
59+
* var sx = [ 12, 12, 4, 2, 1 ];
60+
* var sy = [ 3, 3, 1 ];
61+
*
62+
* // Define the index offsets:
63+
* var ox = 0;
64+
* var oy = 0;
65+
*
66+
* // Create an input ndarray-like object:
67+
* var x = {
68+
* 'dtype': 'float64',
69+
* 'data': xbuf,
70+
* 'shape': xsh,
71+
* 'strides': sx,
72+
* 'offset': ox,
73+
* 'order': 'row-major',
74+
* 'accessors': accessors( xbuf ).accessors
75+
* };
76+
*
77+
* // Create an output ndarray-like object:
78+
* var y = {
79+
* 'dtype': 'generic',
80+
* 'data': ybuf,
81+
* 'shape': ysh,
82+
* 'strides': sy,
83+
* 'offset': oy,
84+
* 'order': 'row-major',
85+
* 'accessors': accessors( ybuf ).accessors
86+
* };
87+
*
88+
* // Initialize ndarray-like objects representing sub-array views:
89+
* var views = [
90+
* {
91+
* 'dtype': x.dtype,
92+
* 'data': x.data,
93+
* 'shape': [ 2, 2 ],
94+
* 'strides': [ 2, 1 ],
95+
* 'offset': x.offset,
96+
* 'order': x.order
97+
* }
98+
* ];
99+
*
100+
* // Perform a reduction:
101+
* unary3d( base, [ x, y ], views, [ 12, 12, 4 ], {} );
102+
*
103+
* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order );
104+
* // returns [ [ [ true, false, true ] ] ]
105+
*/
106+
function unary3d( fcn, arrays, views, strides, opts ) {
107+
var ybuf;
108+
var set;
109+
var dv0;
110+
var dv1;
111+
var dv2;
112+
var sh;
113+
var S0;
114+
var S1;
115+
var S2;
116+
var sv;
117+
var iv;
118+
var i0;
119+
var i1;
120+
var i2;
121+
var y;
122+
var i;
123+
124+
// Note on variable naming convention: S#, dv#, i# where # corresponds to the loop number, with `0` being the innermost loop...
125+
126+
// Resolve the output ndarray and associated shape:
127+
y = arrays[ 1 ];
128+
sh = y.shape;
129+
130+
// Extract loop variables for purposes of loop interchange: dimensions and loop offset (pointer) increments...
131+
if ( isRowMajor( y.order ) ) {
132+
// For row-major ndarrays, the last dimensions have the fastest changing indices...
133+
S0 = sh[ 2 ];
134+
S1 = sh[ 1 ];
135+
S2 = sh[ 0 ];
136+
dv0 = [ strides[2] ];
137+
dv1 = [ strides[1] - ( S0*strides[2] ) ];
138+
dv2 = [ strides[0] - ( S1*strides[1] ) - ( S0*strides[2] ) ];
139+
for ( i = 1; i < arrays.length; i++ ) {
140+
sv = arrays[ i ].strides;
141+
dv0.push( sv[2] );
142+
dv1.push( sv[1] - ( S0*sv[2] ) );
143+
dv2.push( sv[0] - ( S1*sv[1] ) - ( S0*sv[2] ) );
144+
}
145+
} else {
146+
// For column-major ndarrays, the first dimensions have the fastest changing indices...
147+
S0 = sh[ 0 ];
148+
S1 = sh[ 1 ];
149+
S2 = sh[ 2 ];
150+
dv0 = [ strides[0] ];
151+
dv1 = [ strides[1] - ( S0*strides[0] ) ];
152+
dv2 = [ strides[2] - ( S1*strides[1] ) - ( S0*strides[2] ) ];
153+
for ( i = 1; i < arrays.length; i++ ) {
154+
sv = arrays[ i ].strides;
155+
dv0.push( sv[0] );
156+
dv1.push( sv[1] - ( S0*sv[0] ) );
157+
dv2.push( sv[2] - ( S1*sv[1] ) - ( S0*sv[2] ) );
158+
}
159+
}
160+
// Resolve a list of pointers to the first indexed elements in the respective ndarrays:
161+
iv = offsets( arrays );
162+
163+
// Cache a reference to the output ndarray buffer:
164+
ybuf = y.data;
165+
166+
// Cache accessors:
167+
set = y.accessors[ 1 ];
168+
169+
// Iterate over the non-reduced ndarray dimensions...
170+
for ( i2 = 0; i2 < S2; i2++ ) {
171+
for ( i1 = 0; i1 < S1; i1++ ) {
172+
for ( i0 = 0; i0 < S0; i0++ ) {
173+
setViewOffsets( views, iv );
174+
set( ybuf, iv[ 1 ], fcn( views, opts ) );
175+
incrementOffsets( iv, dv0 );
176+
}
177+
incrementOffsets( iv, dv1 );
178+
}
179+
incrementOffsets( iv, dv2 );
180+
}
181+
}
182+
183+
184+
// EXPORTS //
185+
186+
module.exports = unary3d;

0 commit comments

Comments
 (0)