Skip to content

Commit c21f4f5

Browse files
committed
refactor: apply review suggestions
--- 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: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent b6cc39b commit c21f4f5

File tree

10 files changed

+423
-171
lines changed

10 files changed

+423
-171
lines changed

lib/node_modules/@stdlib/blas/ext/find-index/docs/repl.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,3 @@
115115

116116
See Also
117117
--------
118-

lib/node_modules/@stdlib/blas/ext/find-last-index/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ var idx = out.get();
9090
// returns 5
9191

9292
var count = ctx.count;
93-
// returns 6
93+
// returns 1
9494
```
9595

9696
The function accepts the following options:
@@ -99,7 +99,7 @@ The function accepts the following options:
9999
- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`.
100100
- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`.
101101

102-
If no element along an [ndarray][@stdlib/ndarray/ctor] passes a test implemented by the predicate function, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`.
102+
If no element along an [ndarray][@stdlib/ndarray/ctor] dimension passes a test implemented by the predicate function, the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`.
103103

104104
```javascript
105105
var array = require( '@stdlib/ndarray/array' );
@@ -212,7 +212,7 @@ var out = findLastIndex.assign( x, y, isEven );
212212
// returns <ndarray>
213213

214214
var idx = out.get();
215-
// returns 1
215+
// returns 3
216216

217217
var bool = ( out === y );
218218
// returns true

lib/node_modules/@stdlib/blas/ext/find-last-index/docs/repl.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
The callback function should return a boolean.
1313

14-
If no element along an ndarray passes a test implemented by the predicate
15-
function, the corresponding element in the returned ndarray is `-1`.
14+
If no element along an ndarray dimension passes a test implemented by the
15+
predicate function, the corresponding element in the returned ndarray is
16+
`-1`.
1617

1718
Parameters
1819
----------
@@ -68,8 +69,9 @@
6869

6970
The callback function should return a boolean.
7071

71-
If no element along an ndarray passes a test implemented by the predicate
72-
function, the corresponding element in the returned ndarray is `-1`.
72+
If no element along an ndarray dimension passes a test implemented by the
73+
predicate function, the corresponding element in the returned ndarray is
74+
`-1`.
7375

7476
Parameters
7577
----------

lib/node_modules/@stdlib/blas/ext/find-last-index/docs/types/index.d.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -33,48 +33,48 @@ type InputArray<T> = typedndarray<T>;
3333
type OutputArray = typedndarray<number>;
3434

3535
/**
36-
* Returns the result of callback function.
36+
* Returns a boolean indicating whether an element passes a test.
3737
*
38-
* @returns result
38+
* @returns boolean indicating whether an element passes a test
3939
*/
40-
type NullaryCallback<ThisArg> = ( this: ThisArg ) => boolean;
40+
type NullaryPredicate<ThisArg> = ( this: ThisArg ) => boolean;
4141

4242
/**
43-
* Returns the result of callback function.
43+
* Returns a boolean indicating whether an element passes a test.
4444
*
4545
* @param value - current array element
46-
* @returns result
46+
* @returns boolean indicating whether an element passes a test
4747
*/
48-
type UnaryCallback<T, ThisArg> = ( this: ThisArg, value: T ) => boolean;
48+
type UnaryPredicate<T, ThisArg> = ( this: ThisArg, value: T ) => boolean;
4949

5050
/**
51-
* Returns the result of callback function.
51+
* Returns a boolean indicating whether an element passes a test.
5252
*
5353
* @param value - current array element
5454
* @param index - current array element index
55-
* @returns result
55+
* @returns boolean indicating whether an element passes a test
5656
*/
57-
type BinaryCallback<T, ThisArg> = ( this: ThisArg, value: T, index: number ) => boolean;
57+
type BinaryPredicate<T, ThisArg> = ( this: ThisArg, value: T, index: number ) => boolean;
5858

5959
/**
60-
* Returns the result of callback function.
60+
* Returns a boolean indicating whether an element passes a test.
6161
*
6262
* @param value - current array element
6363
* @param index - current array element index
6464
* @param array - input ndarray
65-
* @returns result
65+
* @returns boolean indicating whether an element passes a test
6666
*/
67-
type TernaryCallback<T, U, ThisArg> = ( this: ThisArg, value: T, index: number, array: U ) => boolean;
67+
type TernaryPredicate<T, U, ThisArg> = ( this: ThisArg, value: T, index: number, array: U ) => boolean;
6868

6969
/**
70-
* Returns the result of callback function.
70+
* Returns a boolean indicating whether an element passes a test.
7171
*
7272
* @param value - current array element
7373
* @param index - current array element index
7474
* @param array - input ndarray
75-
* @returns result
75+
* @returns boolean indicating whether an element passes a test
7676
*/
77-
type Callback<T, U, ThisArg> = NullaryCallback<ThisArg> | UnaryCallback<T, ThisArg> | BinaryCallback<T, ThisArg> | TernaryCallback<T, U, ThisArg>;
77+
type Predicate<T, U, ThisArg> = NullaryPredicate<ThisArg> | UnaryPredicate<T, ThisArg> | BinaryPredicate<T, ThisArg> | TernaryPredicate<T, U, ThisArg>;
7878

7979
/**
8080
* Interface defining "base" options.
@@ -113,8 +113,8 @@ interface FindLastIndex {
113113
* Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function.
114114
*
115115
* @param x - input ndarray
116-
* @param clbk - callback function
117-
* @param thisArg - callback function execution context
116+
* @param clbk - predicate function
117+
* @param thisArg - predicate function execution context
118118
* @returns output ndarray
119119
*
120120
* @example
@@ -132,15 +132,15 @@ interface FindLastIndex {
132132
* var v = y.get();
133133
* // returns 1
134134
*/
135-
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): OutputArray;
135+
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, clbk: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): OutputArray;
136136

137137
/**
138138
* Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function.
139139
*
140140
* @param x - input ndarray
141141
* @param options - function options
142-
* @param clbk - callback function
143-
* @param thisArg - callback function execution context
142+
* @param clbk - predicate function
143+
* @param thisArg - predicate function execution context
144144
* @returns output ndarray
145145
*
146146
* @example
@@ -158,15 +158,15 @@ interface FindLastIndex {
158158
* var v = y.get();
159159
* // returns 1
160160
*/
161-
<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;
161+
<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, options: Options, clbk: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): OutputArray;
162162

163163
/**
164164
* Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray.
165165
*
166166
* @param x - input ndarray
167167
* @param out - output ndarray
168-
* @param clbk - callback function
169-
* @param thisArg - callback function execution context
168+
* @param clbk - predicate function
169+
* @param thisArg - predicate function execution context
170170
* @returns output ndarray
171171
*
172172
* @example
@@ -189,16 +189,16 @@ interface FindLastIndex {
189189
* var bool = ( out === y );
190190
* // returns true
191191
*/
192-
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): V;
192+
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, clbk: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): V;
193193

194194
/**
195195
* Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray.
196196
*
197197
* @param x - input ndarray
198198
* @param out - output ndarray
199199
* @param options - function options
200-
* @param clbk - callback function
201-
* @param thisArg - callback function execution context
200+
* @param clbk - predicate function
201+
* @param thisArg - predicate function execution context
202202
* @returns output ndarray
203203
*
204204
* @example
@@ -221,16 +221,16 @@ interface FindLastIndex {
221221
* var bool = ( out === y );
222222
* // returns true
223223
*/
224-
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): V;
224+
assign<T = unknown, U extends InputArray<T> = InputArray<T>, V extends OutputArray = OutputArray, ThisArg = unknown>( x: U, out: V, options: BaseOptions, clbk: Predicate<T, U, ThisArg>, thisArg?: ThisParameterType<Predicate<T, U, ThisArg>> ): V;
225225
}
226226

227227
/**
228228
* Returns the index of the last element along an ndarray dimension which passes a test implemented by a predicate function and assigns results to a provided output ndarray.
229229
*
230230
* @param x - input ndarray
231231
* @param options - function options
232-
* @param clbk - callback function
233-
* @param thisArg - callback execution context
232+
* @param clbk - predicate function
233+
* @param thisArg - Predicate execution context
234234
* @returns output ndarray
235235
*
236236
* @example

lib/node_modules/@stdlib/blas/ext/find-last-index/lib/assign.js

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
2424
var isFunction = require( '@stdlib/assert/is-function' );
2525
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
2626
var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
27-
var getShape = require( '@stdlib/ndarray/shape' );
27+
var ndims = require( '@stdlib/ndarray/ndims' );
2828
var format = require( '@stdlib/string/format' );
2929
var base = require( './base.js' ).assign;
3030

@@ -87,7 +87,7 @@ var base = require( './base.js' ).assign;
8787
* // returns true
8888
*
8989
* var arr = ndarray2array( out );
90-
* // returns [ -1, 1 ]
90+
* // returns [ 1, 2 ]
9191
*/
9292
function assign( x, out ) {
9393
var hasOptions;
@@ -96,7 +96,6 @@ function assign( x, out ) {
9696
var opts;
9797
var ctx;
9898
var cb;
99-
var sh;
10099

101100
nargs = arguments.length;
102101
if ( !isndarrayLike( x ) ) {
@@ -105,10 +104,6 @@ function assign( x, out ) {
105104
if ( !isndarrayLike( out ) ) {
106105
throw new TypeError( format( 'invalid argument. The second argument must be an ndarray. Value: `%s`.', out ) );
107106
}
108-
if ( nargs < 3 ) {
109-
throw new TypeError( format( 'invalid argument. Function must be provided a callback function. Value: `%s`.', arguments[ 2 ] ) );
110-
}
111-
112107
// Initialize an options object:
113108
opts = {
114109
'dims': [ -1 ] // default behavior is to perform a reduction over the last dimension
@@ -118,35 +113,38 @@ function assign( x, out ) {
118113
hasOptions = false;
119114

120115
// Case: assign( x, out, clbk )
121-
if ( nargs === 3 ) {
122-
cb = arguments[ 1 ];
116+
if ( nargs <= 3 ) {
117+
cb = arguments[ 2 ];
123118
if ( !isFunction( cb ) ) {
124-
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) );
119+
throw new TypeError( format( 'invalid argument. Third argument must be a function. Value: `%s`.', cb ) );
125120
}
126121
}
127-
// Case: assign( x, out, options, clbk ) or Case: assign( x, out, clbk, thisArg )
128-
else if ( nargs < 5 ) {
129-
options = arguments[ 2 ];
130-
cb = arguments[ 3 ];
131-
if ( isFunction( options ) ) {
132-
cb = options;
133-
ctx = cb;
134-
} else {
122+
// Case: assign( x, out, ???, ??? )
123+
else if ( nargs === 4 ) {
124+
// Case: assign( x, out, clbk, thisArg )
125+
if ( isFunction( arguments[ 2 ] ) ) {
126+
cb = arguments[ 2 ];
127+
ctx = arguments[ 3 ];
128+
}
129+
// Case: assign( x, out, options, clbk )
130+
else {
131+
options = arguments[ 2 ];
132+
cb = arguments[ 3 ];
135133
if ( !isFunction( cb ) ) {
136-
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) );
134+
throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) );
137135
}
138136
hasOptions = true;
139137
}
140138
}
141139
// Case: assign( x, out, options, clbk, thisArg )
142140
else {
143141
options = arguments[ 2 ];
144-
hasOptions = true;
145142
cb = arguments[ 3 ];
143+
ctx = arguments[ 4 ];
146144
if ( !isFunction( cb ) ) {
147-
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', cb ) );
145+
throw new TypeError( format( 'invalid argument. Fourth argument must be a function. Value: `%s`.', cb ) );
148146
}
149-
ctx = arguments[ 4 ];
147+
hasOptions = true;
150148
}
151149
if ( hasOptions ) {
152150
if ( !isPlainObject( options ) ) {
@@ -157,9 +155,7 @@ function assign( x, out ) {
157155
opts.dims[ 0 ] = options.dim;
158156
}
159157
}
160-
// Resolve the list of non-reduced dimensions:
161-
sh = getShape( x );
162-
if ( sh.length < 1 ) {
158+
if ( ndims( x ) < 1 ) {
163159
throw new RangeError( 'invalid argument. First argument must have at least one dimension.' );
164160
}
165161
return base( x, out, opts, cb, ctx );

lib/node_modules/@stdlib/blas/ext/find-last-index/lib/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ var table = {
8686
* // returns <ndarray>
8787
*
8888
* var idx = out.get();
89-
* // returns 1
89+
* // returns 5
9090
*/
9191
var findLastIndex = factory( table, [ idtypes ], odtypes, policies );
9292

lib/node_modules/@stdlib/blas/ext/find-last-index/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* // returns <ndarray>
5353
*
5454
* var arr = ndarray2array( out );
55-
* // returns [ -1, 1 ]
55+
* // returns [ 1, 2 ]
5656
*/
5757

5858
// MODULES //

0 commit comments

Comments
 (0)