Skip to content

Commit 6837684

Browse files
committed
changes done
1 parent c84342a commit 6837684

3 files changed

Lines changed: 183 additions & 35 deletions

File tree

lib/node_modules/@stdlib/stats/mskmax/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ var v = y.get();
5151
The function has the following parameters:
5252

5353
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or "generic" [data type][@stdlib/ndarray/dtypes].
54-
- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored.
54+
- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored.
5555
- **options**: function options (_optional_).
5656

5757
The function accepts the following options:
@@ -201,7 +201,7 @@ var bool = ( out === y );
201201
The method has the following parameters:
202202

203203
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a real-valued or generic [data type][@stdlib/ndarray/dtypes].
204-
- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must have the same shape as `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored.
204+
- **mask**: mask [ndarray][@stdlib/ndarray/ctor]. Must be [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with `x`. If a mask element is `0`, the corresponding element in `x` is considered valid. If a mask element is non-zero, the corresponding element in `x` is ignored.
205205
- **out**: output [ndarray][@stdlib/ndarray/ctor].
206206
- **options**: function options (_optional_).
207207

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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 dtypes = require( '@stdlib/ndarray/dtypes' );
24+
var gmskmax = require( '@stdlib/stats/base/ndarray/mskmax' );
25+
var dmskmax = require( '@stdlib/stats/base/ndarray/dmskmax' );
26+
var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' );
27+
var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' );
28+
29+
30+
// VARIABLES //
31+
32+
var idtypes = dtypes( 'real_and_generic' );
33+
var mdtypes = dtypes( 'mask_index_and_generic' );
34+
var odtypes = dtypes( 'real_and_generic' );
35+
var policies = {
36+
'output': 'promoted',
37+
'casting': 'none'
38+
};
39+
var table = {
40+
'types': [
41+
'float64',
42+
'uint8', // dmskmax: x, mask
43+
'float32',
44+
'uint8' // smskmax: x, mask
45+
],
46+
'fcns': [
47+
dmskmax,
48+
smskmax
49+
],
50+
'default': gmskmax
51+
};
52+
53+
54+
// MAIN //
55+
56+
/**
57+
* Base implementation for computing the maximum value along one or more ndarray dimensions according to a mask.
58+
*
59+
* @name base
60+
* @type {Function}
61+
* @param {ndarray} x - input ndarray
62+
* @param {ndarray} mask - mask ndarray
63+
* @param {Options} [options] - function options
64+
* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction
65+
* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions
66+
* @param {string} [options.dtype] - output ndarray data type
67+
* @throws {TypeError} first argument must be an ndarray-like object
68+
* @throws {TypeError} second argument must be an ndarray-like object
69+
* @throws {TypeError} options argument must be an object
70+
* @throws {RangeError} dimension indices must not exceed input ndarray bounds
71+
* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions
72+
* @throws {Error} must provide valid options
73+
* @returns {ndarray} output ndarray
74+
*/
75+
var base = factory( table, [ idtypes, mdtypes ], odtypes, policies );
76+
77+
78+
// EXPORTS //
79+
80+
module.exports = base;

lib/node_modules/@stdlib/stats/mskmax/lib/main.js

Lines changed: 101 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,44 +20,17 @@
2020

2121
// MODULES //
2222

23-
var dtypes = require( '@stdlib/ndarray/dtypes' );
24-
var gmskmax = require( '@stdlib/stats/base/ndarray/mskmax' );
25-
var dmskmax = require( '@stdlib/stats/base/ndarray/dmskmax' );
26-
var smskmax = require( '@stdlib/stats/base/ndarray/smskmax' );
27-
var factory = require( '@stdlib/ndarray/base/binary-reduce-strided1d-dispatch-factory' );
28-
29-
30-
// VARIABLES //
31-
32-
var idtypes = dtypes( 'real_and_generic' );
33-
var mdtypes = dtypes( 'integer' );
34-
var odtypes = dtypes( 'real_and_generic' );
35-
var policies = {
36-
'output': 'promoted',
37-
'casting': 'none'
38-
};
39-
var table = {
40-
'types': [
41-
'float64',
42-
'uint8', // dmskmax: x, mask
43-
'float32',
44-
'uint8' // smskmax: x, mask
45-
],
46-
'fcns': [
47-
dmskmax,
48-
smskmax
49-
],
50-
'default': gmskmax
51-
};
23+
var isNdarrayLike = require( '@stdlib/assert/is-ndarray-like' );
24+
var format = require( '@stdlib/string/format' );
25+
var maybeBroadcastArrays = require( '@stdlib/ndarray/base/maybe-broadcast-arrays' );
26+
var base = require( './base.js' );
5227

5328

5429
// MAIN //
5530

5631
/**
5732
* Computes the maximum value along one or more ndarray dimensions according to a mask.
5833
*
59-
* @name max
60-
* @type {Function}
6134
* @param {ndarray} x - input ndarray
6235
* @param {ndarray} mask - mask ndarray
6336
* @param {Options} [options] - function options
@@ -81,7 +54,7 @@ var table = {
8154
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
8255
*
8356
* // Create a mask buffer:
84-
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] ); // eslint-disable-line id-length
57+
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] );
8558
*
8659
* // Define the shape of the input array:
8760
* var sh = [ 3, 2 ];
@@ -107,7 +80,102 @@ var table = {
10780
* var v = out.get();
10881
* // returns 5.0
10982
*/
110-
var mskmax = factory( table, [ idtypes, mdtypes ], odtypes, policies );
83+
function mskmax( x, mask ) {
84+
var arrs;
85+
if ( !isNdarrayLike( x ) ) {
86+
throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );
87+
}
88+
if ( !isNdarrayLike( mask ) ) {
89+
throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', mask ) );
90+
}
91+
arrs = maybeBroadcastArrays( [ x, mask ] );
92+
if ( arguments.length > 2 ) {
93+
return base( arrs[ 0 ], arrs[ 1 ], arguments[ 2 ] );
94+
}
95+
return base( arrs[ 0 ], arrs[ 1 ] );
96+
}
97+
98+
/**
99+
* Computes the maximum value along one or more ndarray dimensions according to a mask and assigns the results to a provided output ndarray.
100+
*
101+
* @name assign
102+
* @memberof mskmax
103+
* @type {Function}
104+
* @param {ndarray} x - input ndarray
105+
* @param {ndarray} mask - mask ndarray
106+
* @param {ndarray} out - output ndarray
107+
* @param {Options} [options] - function options
108+
* @param {IntegerArray} [options.dims] - list of dimensions over which to perform a reduction
109+
* @param {boolean} [options.keepdims=false] - boolean indicating whether the reduced dimensions should be included in the returned ndarray as singleton dimensions
110+
* @throws {TypeError} first argument must be an ndarray-like object
111+
* @throws {TypeError} second argument must be an ndarray-like object
112+
* @throws {TypeError} third argument must be an ndarray-like object
113+
* @throws {TypeError} options argument must be an object
114+
* @throws {RangeError} dimension indices must not exceed input ndarray bounds
115+
* @throws {RangeError} number of dimension indices must not exceed the number of input ndarray dimensions
116+
* @throws {Error} must provide valid options
117+
* @returns {ndarray} output ndarray
118+
*
119+
* @example
120+
* var Float64Array = require( '@stdlib/array/float64' );
121+
* var Uint8Array = require( '@stdlib/array/uint8' );
122+
* var ndarray = require( '@stdlib/ndarray/ctor' );
123+
*
124+
* // Create a data buffer:
125+
* var xbuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
126+
*
127+
* // Create a mask buffer:
128+
* var mbuf = new Uint8Array( [ 0, 0, 0, 1, 0, 1 ] );
129+
*
130+
* // Create an output buffer:
131+
* var obuf = new Float64Array( [ 0.0 ] );
132+
*
133+
* // Define the shape of the input array:
134+
* var sh = [ 3, 2 ];
135+
*
136+
* // Define the array strides:
137+
* var sx = [ 2, 1 ];
138+
* var sm = [ 2, 1 ];
139+
*
140+
* // Define the index offset:
141+
* var ox = 0;
142+
* var om = 0;
143+
*
144+
* // Create the input ndarray:
145+
* var x = new ndarray( 'float64', xbuf, sh, sx, ox, 'row-major' );
146+
*
147+
* // Create the mask ndarray:
148+
* var mask = new ndarray( 'uint8', mbuf, sh, sm, om, 'row-major' ); // cspell:disable-line
149+
*
150+
* // Create the output ndarray:
151+
* var out = new ndarray( 'float64', obuf, [], [ 0 ], 0, 'row-major' );
152+
*
153+
* // Perform reduction:
154+
* var res = mskmax.assign( x, mask, out );
155+
* // returns <ndarray>
156+
*
157+
* var v = res.get();
158+
* // returns 5.0
159+
*/
160+
function assign( x, mask, out ) {
161+
var arrs;
162+
if ( !isNdarrayLike( x ) ) {
163+
throw new TypeError( format( 'invalid argument. First argument must be an ndarray-like object. Value: `%s`.', x ) );
164+
}
165+
if ( !isNdarrayLike( mask ) ) {
166+
throw new TypeError( format( 'invalid argument. Second argument must be an ndarray-like object. Value: `%s`.', mask ) );
167+
}
168+
if ( !isNdarrayLike( out ) ) {
169+
throw new TypeError( format( 'invalid argument. Third argument must be an ndarray-like object. Value: `%s`.', out ) );
170+
}
171+
arrs = maybeBroadcastArrays( [ x, mask ] );
172+
if ( arguments.length > 3 ) {
173+
return base.assign( arrs[ 0 ], arrs[ 1 ], out, arguments[ 3 ] );
174+
}
175+
return base.assign( arrs[ 0 ], arrs[ 1 ], out );
176+
}
177+
178+
mskmax.assign = assign;
111179

112180

113181
// EXPORTS //

0 commit comments

Comments
 (0)