|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# cumin |
| 22 | + |
| 23 | +> Compute the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. |
| 24 | +
|
| 25 | +<section class="usage"> |
| 26 | + |
| 27 | +## Usage |
| 28 | + |
| 29 | +```javascript |
| 30 | +var cumin = require( '@stdlib/stats/cumin' ); |
| 31 | +``` |
| 32 | + |
| 33 | +#### cumin( x\[, options] ) |
| 34 | + |
| 35 | +Computes the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions. |
| 36 | + |
| 37 | +```javascript |
| 38 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 39 | +var array = require( '@stdlib/ndarray/array' ); |
| 40 | + |
| 41 | +var x = array( [ -1.0, 2.0, -3.0 ] ); |
| 42 | + |
| 43 | +var y = cumin( x ); |
| 44 | +// returns <ndarray> |
| 45 | + |
| 46 | +var arr = ndarray2array( y ); |
| 47 | +// returns [ -1.0, -1.0, -3.0 ] |
| 48 | +``` |
| 49 | + |
| 50 | +The function has the following parameters: |
| 51 | + |
| 52 | +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. |
| 53 | +- **options**: function options (_optional_). |
| 54 | + |
| 55 | +The function accepts the following options: |
| 56 | + |
| 57 | +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. |
| 58 | +- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. |
| 59 | + |
| 60 | +By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option. |
| 61 | + |
| 62 | +```javascript |
| 63 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 64 | +var array = require( '@stdlib/ndarray/array' ); |
| 65 | + |
| 66 | +var x = array( [ -1.0, 2.0, -3.0, 4.0 ], { |
| 67 | + 'shape': [ 2, 2 ], |
| 68 | + 'order': 'row-major' |
| 69 | +}); |
| 70 | + |
| 71 | +var v = ndarray2array( x ); |
| 72 | +// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] |
| 73 | + |
| 74 | +var y = cumin( x, { |
| 75 | + 'dims': [ 0 ] |
| 76 | +}); |
| 77 | +// returns <ndarray> |
| 78 | + |
| 79 | +v = ndarray2array( y ); |
| 80 | +// returns [ [ -1.0, 2.0 ], [ -3.0, 2.0 ] ] |
| 81 | + |
| 82 | +y = cumin( x, { |
| 83 | + 'dims': [ 1 ] |
| 84 | +}); |
| 85 | +// returns <ndarray> |
| 86 | + |
| 87 | +v = ndarray2array( y ); |
| 88 | +// returns [ [ -1.0, -1.0 ], [ -3.0, -3.0 ] ] |
| 89 | + |
| 90 | +y = cumin( x, { |
| 91 | + 'dims': [ 0, 1 ] |
| 92 | +}); |
| 93 | +// returns <ndarray> |
| 94 | + |
| 95 | +v = ndarray2array( y ); |
| 96 | +// returns [ [ -1.0, -1.0 ], [ -3.0, -3.0 ] ] |
| 97 | +``` |
| 98 | + |
| 99 | +By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option. |
| 100 | + |
| 101 | +```javascript |
| 102 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 103 | +var getDType = require( '@stdlib/ndarray/dtype' ); |
| 104 | +var array = require( '@stdlib/ndarray/array' ); |
| 105 | + |
| 106 | +var x = array( [ -1.0, 2.0, -3.0 ], { |
| 107 | + 'dtype': 'generic' |
| 108 | +}); |
| 109 | + |
| 110 | +var y = cumin( x, { |
| 111 | + 'dtype': 'float64' |
| 112 | +}); |
| 113 | +// returns <ndarray> |
| 114 | + |
| 115 | +var dt = getDType( y ); |
| 116 | +// returns 'float64' |
| 117 | +``` |
| 118 | + |
| 119 | +#### cumin.assign( x, out\[, options] ) |
| 120 | + |
| 121 | +Computes the cumulative minimum value along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor]. |
| 122 | + |
| 123 | +```javascript |
| 124 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 125 | +var array = require( '@stdlib/ndarray/array' ); |
| 126 | +var zerosLike = require( '@stdlib/ndarray/zeros-like' ); |
| 127 | + |
| 128 | +var x = array( [ -1.0, 2.0, -3.0 ] ); |
| 129 | +var y = zerosLike( x ); |
| 130 | + |
| 131 | +var out = cumin.assign( x, y ); |
| 132 | +// returns <ndarray> |
| 133 | + |
| 134 | +var v = ndarray2array( out ); |
| 135 | +// returns [ -1.0, -1.0, -3.0 ] |
| 136 | + |
| 137 | +var bool = ( out === y ); |
| 138 | +// returns true |
| 139 | +``` |
| 140 | + |
| 141 | +The method has the following parameters: |
| 142 | + |
| 143 | +- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or generic [data type][@stdlib/ndarray/dtypes]. |
| 144 | +- **out**: output [ndarray][@stdlib/ndarray/ctor]. |
| 145 | +- **options**: function options (_optional_). |
| 146 | + |
| 147 | +The method accepts the following options: |
| 148 | + |
| 149 | +- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. |
| 150 | + |
| 151 | +</section> |
| 152 | + |
| 153 | +<!-- /.usage --> |
| 154 | + |
| 155 | +<section class="notes"> |
| 156 | + |
| 157 | +## Notes |
| 158 | + |
| 159 | +- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. |
| 160 | +- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having the same [data type][@stdlib/ndarray/dtypes] as the input [ndarray][@stdlib/ndarray/ctor]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes]. |
| 161 | + |
| 162 | +</section> |
| 163 | + |
| 164 | +<!-- /.notes --> |
| 165 | + |
| 166 | +<section class="examples"> |
| 167 | + |
| 168 | +## Examples |
| 169 | + |
| 170 | +<!-- eslint no-undef: "error" --> |
| 171 | + |
| 172 | +```javascript |
| 173 | +var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); |
| 174 | +var getDType = require( '@stdlib/ndarray/dtype' ); |
| 175 | +var ndarray2array = require( '@stdlib/ndarray/to-array' ); |
| 176 | +var ndarray = require( '@stdlib/ndarray/ctor' ); |
| 177 | +var cumin = require( '@stdlib/stats/cumin' ); |
| 178 | + |
| 179 | +// Generate an array of random numbers: |
| 180 | +var xbuf = discreteUniform( 25, 0, 20, { |
| 181 | + 'dtype': 'generic' |
| 182 | +}); |
| 183 | + |
| 184 | +// Wrap in an ndarray: |
| 185 | +var x = new ndarray( 'generic', xbuf, [ 5, 5 ], [ 5, 1 ], 0, 'row-major' ); |
| 186 | +console.log( ndarray2array( x ) ); |
| 187 | + |
| 188 | +// Perform operation: |
| 189 | +var y = cumin( x, { |
| 190 | + 'dims': [ 0 ] |
| 191 | +}); |
| 192 | + |
| 193 | +// Resolve the output array data type: |
| 194 | +var dt = getDType( y ); |
| 195 | +console.log( dt ); |
| 196 | + |
| 197 | +// Print the results: |
| 198 | +console.log( ndarray2array( y ) ); |
| 199 | +``` |
| 200 | + |
| 201 | +</section> |
| 202 | + |
| 203 | +<!-- /.examples --> |
| 204 | + |
| 205 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 206 | + |
| 207 | +<section class="related"> |
| 208 | + |
| 209 | +</section> |
| 210 | + |
| 211 | +<!-- /.related --> |
| 212 | + |
| 213 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 214 | + |
| 215 | +<section class="links"> |
| 216 | + |
| 217 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor |
| 218 | + |
| 219 | +[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes |
| 220 | + |
| 221 | +[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies |
| 222 | + |
| 223 | +</section> |
| 224 | + |
| 225 | +<!-- /.links --> |
0 commit comments