Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 10 additions & 40 deletions lib/node_modules/@stdlib/stats/max-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ function clbk( v ) {
}

var y = maxBy( x, clbk );
// returns <ndarray>

var v = y.get();
// returns 4.0
// returns <ndarray>[ 4.0 ]
```

The function has the following parameters:
Expand Down Expand Up @@ -99,7 +96,6 @@ The function accepts the following options:
By default, the function performs a reduction over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform a reduction over specific dimensions, provide a `dims` option.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

function clbk( v ) {
Expand All @@ -110,41 +106,30 @@ var x = array( [ -1.0, 2.0, -3.0, 4.0 ], {
'shape': [ 2, 2 ],
'order': 'row-major'
});
var v = ndarray2array( x );
// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]
// returns <ndarray>[ <ndarray>[ -1.0, 2.0 ], <ndarray>[ -3.0, 4.0 ] ]

var opts = {
'dims': [ 0 ]
};
var y = maxBy( x, opts, clbk );
// returns <ndarray>

v = ndarray2array( y );
// returns [ -100.0, 400.0 ]
// returns <ndarray>[ -100.0, 400.0 ]

opts = {
'dims': [ 1 ]
};
y = maxBy( x, opts, clbk );
// returns <ndarray>

v = ndarray2array( y );
// returns [ 200.0, 400.0 ]
// returns <ndarray>[ 200.0, 400.0 ]

opts = {
'dims': [ 0, 1 ]
};
y = maxBy( x, opts, clbk );
// returns <ndarray>

v = y.get();
// returns 400.0
// returns <ndarray>[ 400.0 ]
```

By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

function clbk( v ) {
Expand All @@ -156,38 +141,26 @@ var x = array( [ -1.0, 2.0, -3.0, 4.0 ], {
'order': 'row-major'
});

var v = ndarray2array( x );
// returns [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ]

var opts = {
'dims': [ 0 ],
'keepdims': true
};
var y = maxBy( x, opts, clbk );
// returns <ndarray>

v = ndarray2array( y );
// returns [ [ -100.0, 400.0 ] ]
// returns <ndarray>[ [ -100.0, 400.0 ] ]

opts = {
'dims': [ 1 ],
'keepdims': true
};
y = maxBy( x, opts, clbk );
// returns <ndarray>

v = ndarray2array( y );
// returns [ [ 200.0 ], [ 400.0 ] ]
// returns <ndarray>[ [ 200.0 ], [ 400.0 ] ]

opts = {
'dims': [ 0, 1 ],
'keepdims': true
};
y = maxBy( x, opts, clbk );
// returns <ndarray>

v = ndarray2array( y );
// returns [ [ 400.0 ] ]
// returns <ndarray>[ [ 400.0 ] ]
```

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.
Expand All @@ -208,7 +181,7 @@ var opts = {
'dtype': 'float64'
};
var y = maxBy( x, opts, clbk );
// returns <ndarray>
// returns <ndarray>[ 200.0 ]

var dt = String( getDType( y ) );
// returns 'float64'
Expand All @@ -230,10 +203,7 @@ var x = array( [ -1.0, 2.0, -3.0 ] );
var y = zeros( [] );

var out = maxBy.assign( x, y, clbk );
// returns <ndarray>

var v = out.get();
// returns 200.0
// returns <ndarray>[ 200.0 ]

var bool = ( out === y );
// returns true
Expand Down
9 changes: 3 additions & 6 deletions lib/node_modules/@stdlib/stats/max-by/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@
--------
> var x = {{alias:@stdlib/ndarray/array}}( [ -1.0, 2.0, -3.0, -4.0 ] );
> function clbk( v ) { return v * 2.0; };
> var y = {{alias}}( x, clbk );
> var v = y.get()
4.0
> var y = {{alias}}( x, clbk )
<ndarray>[ 4.0 ]


{{alias}}.assign( x, out[, options], clbk[, thisArg] )
Expand Down Expand Up @@ -102,11 +101,9 @@
> var out = {{alias:@stdlib/ndarray/zeros}}( [] );
> function clbk( v ) { return v * 2.0; };
> var y = {{alias}}.assign( x, out, clbk )
<ndarray>
<ndarray>[ 4.0 ]
> var bool = ( out === y )
true
> var v = out.get()
4.0

See Also
--------
Expand Down
30 changes: 6 additions & 24 deletions lib/node_modules/@stdlib/stats/max-by/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ interface Unary {
* var x = array( [ -1.0, 2.0, -3.0 ] );
*
* var y = maxBy( x, clbk );
* // returns <ndarray>
*
* var v = y.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*/
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): OutputArray<number>; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`.

Expand All @@ -150,10 +147,7 @@ interface Unary {
* var x = array( [ -1.0, 2.0, -3.0 ] );
*
* var y = maxBy( x, {}, clbk );
* // returns <ndarray>
*
* var v = y.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*/
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, options: Options, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): OutputArray<number>; // NOTE: we lose type specificity here, but retaining specificity would likely be difficult and/or tedious to completely enumerate, as the output ndarray data type is dependent on how `x` interacts with output data type policy and whether that policy has been overridden by `options.dtype`.

Expand All @@ -178,10 +172,7 @@ interface Unary {
* }
*
* var out = maxBy.assign( x, y, clbk );
* // returns <ndarray>
*
* var v = out.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*
* var bool = ( out === y );
* // returns true
Expand Down Expand Up @@ -210,10 +201,7 @@ interface Unary {
* }
*
* var out = maxBy.assign( x, y, {}, clbk );
* // returns <ndarray>
*
* var v = out.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*
* var bool = ( out === y );
* // returns true
Expand All @@ -240,10 +228,7 @@ interface Unary {
* }
*
* var y = maxBy( x, clbk );
* // returns <ndarray>
*
* var v = y.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*
* @example
* var array = require( '@stdlib/ndarray/array' );
Expand All @@ -257,10 +242,7 @@ interface Unary {
* }
*
* var out = maxBy.assign( x, y, clbk );
* // returns <ndarray>
*
* var v = out.get();
* // returns 4.0
* // returns <ndarray>[ 4.0 ]
*
* var bool = ( out === y );
* // returns true
Expand Down
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/stats/max-by/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
*
* // Perform reduction:
* var out = maxBy( x, clbk );
* // returns <ndarray>
*
* var v = out.get();
* // returns 22.0
* // returns <ndarray>[ 22.0 ]
*/

// MODULES //
Expand Down
5 changes: 1 addition & 4 deletions lib/node_modules/@stdlib/stats/max-by/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,7 @@ var table = {
*
* // Perform reduction:
* var out = maxBy( x, clbk );
* // returns <ndarray>
*
* var v = out.get();
* // returns 22.0
* // returns <ndarray>[ 22.0 ]
*/
var maxBy = factory( table, [ idtypes ], odtypes, policies );

Expand Down