|
| 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 | +/** |
| 22 | +* Perform a reduction over a list of specified dimensions in an input ndarray via a one-dimensional strided array reduction function and assign results to a provided output ndarray. |
| 23 | +* |
| 24 | +* @module @stdlib/ndarray/base/unary-reduce-strided1d-to-struct |
| 25 | +* |
| 26 | +* @example |
| 27 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 28 | +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 29 | +* var Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' ); |
| 30 | +* var structFactory = require( '@stdlib/array/struct-factory' ); |
| 31 | +* var ztest = require( '@stdlib/stats/base/ndarray/ztest' ); |
| 32 | +* var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d-to-struct' ); |
| 33 | +* |
| 34 | +* var ResultsArray = structFactory( Float64Results ); |
| 35 | +* |
| 36 | +* // Create data buffers: |
| 37 | +* 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 ] ); |
| 38 | +* var ybuf = new ResultsArray( 3 ); |
| 39 | +* |
| 40 | +* // Define the array shapes: |
| 41 | +* var xsh = [ 1, 3, 2, 2 ]; |
| 42 | +* var ysh = [ 1, 3 ]; |
| 43 | +* |
| 44 | +* // Define the array strides: |
| 45 | +* var sx = [ 12, 4, 2, 1 ]; |
| 46 | +* var sy = [ 3, 1 ]; |
| 47 | +* |
| 48 | +* // Define the index offsets: |
| 49 | +* var ox = 0; |
| 50 | +* var oy = 0; |
| 51 | +* |
| 52 | +* // Create an input ndarray-like object: |
| 53 | +* var x = { |
| 54 | +* 'dtype': 'float64', |
| 55 | +* 'data': xbuf, |
| 56 | +* 'shape': xsh, |
| 57 | +* 'strides': sx, |
| 58 | +* 'offset': ox, |
| 59 | +* 'order': 'row-major' |
| 60 | +* }; |
| 61 | +* |
| 62 | +* // Create an output ndarray-like object: |
| 63 | +* var y = { |
| 64 | +* 'dtype': Float64Results, |
| 65 | +* 'data': ybuf, |
| 66 | +* 'shape': ysh, |
| 67 | +* 'strides': sy, |
| 68 | +* 'offset': oy, |
| 69 | +* 'order': 'row-major' |
| 70 | +* }; |
| 71 | +* |
| 72 | +* // Create additional parameter ndarray-like objects: |
| 73 | +* var alternative = { |
| 74 | +* 'dtype': 'generic', |
| 75 | +* 'data': [ 'two-sided' ], |
| 76 | +* 'shape': ysh, |
| 77 | +* 'strides': [ 0, 0 ], |
| 78 | +* 'offset': 0, |
| 79 | +* 'order': 'row-major' |
| 80 | +}; |
| 81 | +* var alpha = { |
| 82 | +* 'dtype': 'float64', |
| 83 | +* 'data': [ 0.05 ], |
| 84 | +* 'shape': ysh, |
| 85 | +* 'strides': [ 0, 0 ], |
| 86 | +* 'offset': 0, |
| 87 | +* 'order': 'row-major' |
| 88 | +}; |
| 89 | +* var mu = { |
| 90 | +* 'dtype': 'float64', |
| 91 | +* 'data': [ 0.0 ], |
| 92 | +* 'shape': ysh, |
| 93 | +* 'strides': [ 0, 0 ], |
| 94 | +* 'offset': 0, |
| 95 | +* 'order': 'row-major' |
| 96 | +}; |
| 97 | +* var sigma = { |
| 98 | +* 'dtype': 'float64', |
| 99 | +* 'data': [ 1.0 ], |
| 100 | +* 'shape': ysh, |
| 101 | +* 'strides': [ 0, 0 ], |
| 102 | +* 'offset': 0, |
| 103 | +* 'order': 'row-major' |
| 104 | +* }; |
| 105 | +* |
| 106 | +* // Perform a reduction: |
| 107 | +* unaryReduceStrided1d( ztest, [ x, y, alternative, alpha, mu, sigma ], [ 2, 3 ] ); |
| 108 | +* |
| 109 | +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); |
| 110 | +* // returns [ [ <Float64Results>, <Float64Results>, <Float64Results> ] ] |
| 111 | +* |
| 112 | +* @example |
| 113 | +* var Float64Array = require( '@stdlib/array/float64' ); |
| 114 | +* var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); |
| 115 | +* var Float64Results = require( '@stdlib/stats/base/ztest/one-sample/results/float64' ); |
| 116 | +* var structFactory = require( '@stdlib/array/struct-factory' ); |
| 117 | +* var base = require( '@stdlib/stats/base/ndarray/ztest' ); |
| 118 | +* var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d-to-struct' ); |
| 119 | +* |
| 120 | +* var ResultsArray = structFactory( Float64Results ); |
| 121 | +* |
| 122 | +* // Create data buffers: |
| 123 | +* 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 ] ); |
| 124 | +* var ybuf = new ResultsArray( 3 ); |
| 125 | +* |
| 126 | +* // Define the array shapes: |
| 127 | +* var xsh = [ 1, 3, 2, 2 ]; |
| 128 | +* var ysh = [ 1, 3 ]; |
| 129 | +* |
| 130 | +* // Define the array strides: |
| 131 | +* var sx = [ 12, 4, 2, 1 ]; |
| 132 | +* var sy = [ 3, 1 ]; |
| 133 | +* |
| 134 | +* // Define the index offsets: |
| 135 | +* var ox = 0; |
| 136 | +* var oy = 0; |
| 137 | +* |
| 138 | +* // Create an input ndarray-like object: |
| 139 | +* var x = { |
| 140 | +* 'dtype': 'float64', |
| 141 | +* 'data': xbuf, |
| 142 | +* 'shape': xsh, |
| 143 | +* 'strides': sx, |
| 144 | +* 'offset': ox, |
| 145 | +* 'order': 'row-major' |
| 146 | +* }; |
| 147 | +* |
| 148 | +* // Create an output ndarray-like object: |
| 149 | +* var y = { |
| 150 | +* 'dtype': Float64Results, |
| 151 | +* 'data': ybuf, |
| 152 | +* 'shape': ysh, |
| 153 | +* 'strides': sy, |
| 154 | +* 'offset': oy, |
| 155 | +* 'order': 'row-major' |
| 156 | +* }; |
| 157 | +* |
| 158 | +* // Create additional parameter ndarray-like objects: |
| 159 | +* var alternative = { |
| 160 | +* 'dtype': 'generic', |
| 161 | +* 'data': [ 'two-sided' ], |
| 162 | +* 'shape': ysh, |
| 163 | +* 'strides': [ 0, 0 ], |
| 164 | +* 'offset': 0, |
| 165 | +* 'order': 'row-major' |
| 166 | +}; |
| 167 | +* var alpha = { |
| 168 | +* 'dtype': 'float64', |
| 169 | +* 'data': [ 0.05 ], |
| 170 | +* 'shape': ysh, |
| 171 | +* 'strides': [ 0, 0 ], |
| 172 | +* 'offset': 0, |
| 173 | +* 'order': 'row-major' |
| 174 | +}; |
| 175 | +* var mu = { |
| 176 | +* 'dtype': 'float64', |
| 177 | +* 'data': [ 0.0 ], |
| 178 | +* 'shape': ysh, |
| 179 | +* 'strides': [ 0, 0 ], |
| 180 | +* 'offset': 0, |
| 181 | +* 'order': 'row-major' |
| 182 | +}; |
| 183 | +* var sigma = { |
| 184 | +* 'dtype': 'float64', |
| 185 | +* 'data': [ 1.0 ], |
| 186 | +* 'shape': ysh, |
| 187 | +* 'strides': [ 0, 0 ], |
| 188 | +* 'offset': 0, |
| 189 | +* 'order': 'row-major' |
| 190 | +* }; |
| 191 | +* |
| 192 | +* // Create a function for performing a reduction over subarrays: |
| 193 | +* var ztest = unaryReduceStrided1d.factory( base ); |
| 194 | +* // returns <Function> |
| 195 | +* |
| 196 | +* // Perform a reduction: |
| 197 | +* ztest( [ x, y, alternative, alpha, mu, sigma ], [ 2, 3 ] ); |
| 198 | +* |
| 199 | +* var arr = ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ); |
| 200 | +* // returns [ [ <Float64Results>, <Float64Results>, <Float64Results> ] ] |
| 201 | +*/ |
| 202 | + |
| 203 | +// MODULES // |
| 204 | + |
| 205 | +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); |
| 206 | +var main = require( './main.js' ); |
| 207 | +var factory = require( './factory.js' ); |
| 208 | + |
| 209 | + |
| 210 | +// MAIN // |
| 211 | + |
| 212 | +setReadOnly( main, 'factory', factory ); |
| 213 | + |
| 214 | + |
| 215 | +// EXPORTS // |
| 216 | + |
| 217 | +module.exports = main; |
| 218 | + |
| 219 | +// exports: { "factory": "main.factory" } |
0 commit comments