Skip to content

Commit c9b5f5e

Browse files
committed
feat: add 0d kernel
--- 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 6bc3cd0 commit c9b5f5e

File tree

1 file changed

+138
-0
lines changed
  • lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-to-struct/lib

1 file changed

+138
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
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+
* Performs a reduction over a list of specified dimensions in an input ndarray and assigns results to a provided output ndarray.
25+
*
26+
* @private
27+
* @param {Function} fcn - wrapper for a one-dimensional strided array reduction function
28+
* @param {Array<Object>} arrays - ndarrays
29+
* @param {Function} strategy - input ndarray reshape strategy
30+
* @param {Options} opts - function options
31+
* @returns {void}
32+
*
33+
* @example
34+
* var Float64Array = require( '@stdlib/array/float64' );
35+
* var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
36+
* var Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' );
37+
* var structFactory = require( '@stdlib/array/struct-factory' );
38+
* var ztest = require( '@stdlib/stats/base/ndarray/ztest' );
39+
*
40+
* var ResultsArray = structFactory( Float64Results );
41+
*
42+
* // Create data buffers:
43+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
44+
* var ybuf = new ResultsArray( 1 );
45+
*
46+
* // Define the array shapes:
47+
* var xsh = [ 2, 2 ];
48+
* var ysh = [];
49+
*
50+
* // Define the array strides:
51+
* var sx = [ 2, 1 ];
52+
* var sy = [ 0 ];
53+
*
54+
* // Define the index offsets:
55+
* var ox = 0;
56+
* var oy = 0;
57+
*
58+
* // Create an input ndarray-like object:
59+
* var x = {
60+
* 'dtype': 'float64',
61+
* 'data': xbuf,
62+
* 'shape': xsh,
63+
* 'strides': sx,
64+
* 'offset': ox,
65+
* 'order': 'row-major'
66+
* };
67+
*
68+
* // Create an output ndarray-like object:
69+
* var y = {
70+
* 'dtype': Float64Results,
71+
* 'data': ybuf,
72+
* 'shape': ysh,
73+
* 'strides': sy,
74+
* 'offset': oy,
75+
* 'order': 'row-major'
76+
* };
77+
*
78+
* // Create additional parameter ndarray-like objects:
79+
* var alternative = {
80+
* 'dtype': 'generic',
81+
* 'data': [ 'two-sided' ],
82+
* 'shape': ysh,
83+
* 'strides': [ 0 ],
84+
* 'offset': 0,
85+
* 'order': 'row-major'
86+
};
87+
* var alpha = {
88+
* 'dtype': 'float64',
89+
* 'data': [ 0.05 ],
90+
* 'shape': ysh,
91+
* 'strides': [ 0 ],
92+
* 'offset': 0,
93+
* 'order': 'row-major'
94+
};
95+
* var mu = {
96+
* 'dtype': 'float64',
97+
* 'data': [ 0.0 ],
98+
* 'shape': ysh,
99+
* 'strides': [ 0 ],
100+
* 'offset': 0,
101+
* 'order': 'row-major'
102+
};
103+
* var sigma = {
104+
* 'dtype': 'float64',
105+
* 'data': [ 1.0 ],
106+
* 'shape': ysh,
107+
* 'strides': [ 0 ],
108+
* 'offset': 0,
109+
* 'order': 'row-major'
110+
* };
111+
*
112+
* // Define a reshape strategy:
113+
* function strategy( x ) {
114+
* return {
115+
* 'dtype': x.dtype,
116+
* 'data': x.data,
117+
* 'shape': [ 4 ],
118+
* 'strides': [ 1 ],
119+
* 'offset': x.offset,
120+
* 'order': x.order
121+
* };
122+
* }
123+
*
124+
* // Perform a reduction:
125+
* unary0d( ztest, [ x, y, alternative, alpha, mu, sigma ], strategy, {} );
126+
*
127+
* var v = y.data.get( 0 );
128+
* // returns <Float64Results>
129+
*/
130+
function unary0d( fcn, arrays, strategy, opts ) {
131+
arrays[ 0 ] = strategy( arrays[ 0 ] );
132+
fcn( arrays, opts );
133+
}
134+
135+
136+
// EXPORTS //
137+
138+
module.exports = unary0d;

0 commit comments

Comments
 (0)