Skip to content

Commit 5396232

Browse files
committed
refactor: use base utility
--- 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: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - 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: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 24c59ca commit 5396232

File tree

7 files changed

+21
-169
lines changed
  • lib/node_modules/@stdlib/ndarray
    • base
      • binary-reduce-strided1d-dispatch/lib
      • nullary-strided1d-dispatch/lib
      • unary-reduce-strided1d-dispatch-by/lib
      • unary-reduce-strided1d-dispatch/lib
      • unary-strided1d-dispatch/lib
    • dispatch-by/lib
    • dispatch/lib

7 files changed

+21
-169
lines changed

lib/node_modules/@stdlib/ndarray/base/binary-reduce-strided1d-dispatch/lib/main.js

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var contains = require( '@stdlib/array/base/assert/contains' );
3737
var binaryReduceStrided1d = require( '@stdlib/ndarray/base/binary-reduce-strided1d' );
3838
var binaryOutputDataType = require( '@stdlib/ndarray/base/binary-output-dtype' );
3939
var binaryInputCastingDataType = require( '@stdlib/ndarray/base/binary-input-casting-dtype' );
40-
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
40+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
4141
var spreadDimensions = require( '@stdlib/ndarray/base/spread-dimensions' );
4242
var getShape = require( '@stdlib/ndarray/shape' ); // note: non-base accessor is intentional due to input ndarrays originating in userland
4343
var ndims = require( '@stdlib/ndarray/ndims' );
@@ -66,27 +66,6 @@ var indexOfTypes = require( './index_of_types.js' );
6666
var DEFAULT_ORDER = defaults.get( 'order' );
6767

6868

69-
// FUNCTIONS //
70-
71-
/**
72-
* Returns a list of data type enumeration constants.
73-
*
74-
* @private
75-
* @param {Collection} types - list of types
76-
* @returns {IntegerArray} list of data type enumeration constants
77-
*/
78-
function types2enums( types ) {
79-
var out;
80-
var i;
81-
82-
out = [];
83-
for ( i = 0; i < types.length; i++ ) {
84-
out.push( resolveEnum( types[ i ] ) ); // note: we're assuming that `types[i]` is a known data type; otherwise, the resolved enum will be `null`
85-
}
86-
return out;
87-
}
88-
89-
9069
// MAIN //
9170

9271
/**
@@ -187,7 +166,7 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
187166
}
188167
this._table = {
189168
'default': table.default,
190-
'types': ( table.types ) ? types2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
169+
'types': ( table.types ) ? dtypes2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
191170
'fcns': ( table.fcns ) ? copy( table.fcns ) : []
192171
};
193172
if ( this._table.types.length !== 2 * this._table.fcns.length ) {
@@ -254,7 +233,6 @@ function BinaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
254233
*/
255234
setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y ) {
256235
var options;
257-
var dtypes;
258236
var nargs;
259237
var args;
260238
var opts;
@@ -375,8 +353,7 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
375353
ydt = dt;
376354
}
377355
// Resolve the lower-level strided function satisfying the input ndarray data types:
378-
dtypes = [ resolveEnum( xdt ), resolveEnum( ydt ) ];
379-
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len
356+
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes2enums( [ xdt, ydt ] ), 1, 0 ); // eslint-disable-line max-len
380357
if ( i >= 0 ) {
381358
f = this._table.fcns[ i ];
382359
} else {
@@ -452,7 +429,6 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'apply', function apply( x, y )
452429
*/
453430
setReadOnly( BinaryStrided1dDispatch.prototype, 'assign', function assign( x, y ) {
454431
var options;
455-
var dtypes;
456432
var nargs;
457433
var opts;
458434
var args;
@@ -565,8 +541,7 @@ setReadOnly( BinaryStrided1dDispatch.prototype, 'assign', function assign( x, y
565541
ydt = dt;
566542
}
567543
// Resolve the lower-level strided function satisfying the input ndarray data type:
568-
dtypes = [ resolveEnum( xdt ), resolveEnum( ydt ) ];
569-
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len
544+
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes2enums( [ xdt, ydt ] ), 1, 0 ); // eslint-disable-line max-len
570545
if ( i >= 0 ) {
571546
f = this._table.fcns[ i ];
572547
} else {

lib/node_modules/@stdlib/ndarray/base/nullary-strided1d-dispatch/lib/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
3434
var contains = require( '@stdlib/array/base/assert/contains' );
3535
var nullaryStrided1d = require( '@stdlib/ndarray/base/nullary-strided1d' );
3636
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
37+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
3738
var ndims = require( '@stdlib/ndarray/ndims' );
3839
var getDType = require( '@stdlib/ndarray/base/dtype' );
3940
var zeroTo = require( '@stdlib/array/base/zero-to' );
@@ -47,27 +48,6 @@ var validate = require( './validate.js' );
4748
var indexOfTypes = require( './index_of_types.js' );
4849

4950

50-
// FUNCTIONS //
51-
52-
/**
53-
* Returns a list of data type enumeration constants.
54-
*
55-
* @private
56-
* @param {Collection} types - list of types
57-
* @returns {IntegerArray} list of data type enumeration constants
58-
*/
59-
function types2enums( types ) {
60-
var out;
61-
var i;
62-
63-
out = [];
64-
for ( i = 0; i < types.length; i++ ) {
65-
out.push( resolveEnum( types[ i ] ) ); // note: we're assuming that `types[i]` is a known data type; otherwise, the resolved enum will be `null`
66-
}
67-
return out;
68-
}
69-
70-
7151
// MAIN //
7252

7353
/**
@@ -160,7 +140,7 @@ function NullaryStrided1dDispatch( table, idtypes, odtypes, options ) {
160140
}
161141
this._table = {
162142
'default': table.default,
163-
'types': ( table.types ) ? types2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
143+
'types': ( table.types ) ? dtypes2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
164144
'fcns': ( table.fcns ) ? copy( table.fcns ) : []
165145
};
166146
if ( this._table.types.length !== this._table.fcns.length ) {

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch-by/lib/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var unaryReduceStrided1dBy = require( '@stdlib/ndarray/base/unary-reduce-strided
3838
var unaryOutputDataType = require( '@stdlib/ndarray/base/unary-output-dtype' );
3939
var unaryInputCastingDataType = require( '@stdlib/ndarray/base/unary-input-casting-dtype' );
4040
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
41+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
4142
var spreadDimensions = require( '@stdlib/ndarray/base/spread-dimensions' );
4243
var getShape = require( '@stdlib/ndarray/shape' ); // note: non-base accessor is intentional due to input ndarrays originating in userland
4344
var ndims = require( '@stdlib/ndarray/ndims' );
@@ -60,27 +61,6 @@ var validate = require( './validate.js' );
6061
var indexOfTypes = require( './index_of_types.js' );
6162

6263

63-
// FUNCTIONS //
64-
65-
/**
66-
* Returns a list of data type enumeration constants.
67-
*
68-
* @private
69-
* @param {Collection} types - list of types
70-
* @returns {IntegerArray} list of data type enumeration constants
71-
*/
72-
function types2enums( types ) {
73-
var out;
74-
var i;
75-
76-
out = [];
77-
for ( i = 0; i < types.length; i++ ) {
78-
out.push( resolveEnum( types[ i ] ) ); // note: we're assuming that `types[i]` is a known data type; otherwise, the resolved enum will be `null`
79-
}
80-
return out;
81-
}
82-
83-
8464
// MAIN //
8565

8666
/**
@@ -182,7 +162,7 @@ function UnaryStrided1dDispatchBy( table, idtypes, odtypes, policies ) {
182162
}
183163
this._table = {
184164
'default': table.default,
185-
'types': ( table.types ) ? types2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
165+
'types': ( table.types ) ? dtypes2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
186166
'fcns': ( table.fcns ) ? copy( table.fcns ) : []
187167
};
188168
if ( this._table.types.length !== this._table.fcns.length ) {

lib/node_modules/@stdlib/ndarray/base/unary-reduce-strided1d-dispatch/lib/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var unaryReduceStrided1d = require( '@stdlib/ndarray/base/unary-reduce-strided1d
3838
var unaryOutputDataType = require( '@stdlib/ndarray/base/unary-output-dtype' );
3939
var unaryInputCastingDataType = require( '@stdlib/ndarray/base/unary-input-casting-dtype' );
4040
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
41+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
4142
var spreadDimensions = require( '@stdlib/ndarray/base/spread-dimensions' );
4243
var getShape = require( '@stdlib/ndarray/shape' ); // note: non-base accessor is intentional due to input ndarrays originating in userland
4344
var ndims = require( '@stdlib/ndarray/ndims' );
@@ -60,27 +61,6 @@ var validate = require( './validate.js' );
6061
var indexOfTypes = require( './index_of_types.js' );
6162

6263

63-
// FUNCTIONS //
64-
65-
/**
66-
* Returns a list of data type enumeration constants.
67-
*
68-
* @private
69-
* @param {Collection} types - list of types
70-
* @returns {IntegerArray} list of data type enumeration constants
71-
*/
72-
function types2enums( types ) {
73-
var out;
74-
var i;
75-
76-
out = [];
77-
for ( i = 0; i < types.length; i++ ) {
78-
out.push( resolveEnum( types[ i ] ) ); // note: we're assuming that `types[i]` is a known data type; otherwise, the resolved enum will be `null`
79-
}
80-
return out;
81-
}
82-
83-
8464
// MAIN //
8565

8666
/**
@@ -178,7 +158,7 @@ function UnaryStrided1dDispatch( table, idtypes, odtypes, policies ) {
178158
}
179159
this._table = {
180160
'default': table.default,
181-
'types': ( table.types ) ? types2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
161+
'types': ( table.types ) ? dtypes2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
182162
'fcns': ( table.fcns ) ? copy( table.fcns ) : []
183163
};
184164
if ( this._table.types.length !== this._table.fcns.length ) {

lib/node_modules/@stdlib/ndarray/base/unary-strided1d-dispatch/lib/main.js

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ var contains = require( '@stdlib/array/base/assert/contains' );
3737
var unaryStrided1d = require( '@stdlib/ndarray/base/unary-strided1d' );
3838
var unaryOutputDataType = require( '@stdlib/ndarray/base/unary-output-dtype' );
3939
var unaryInputCastingDataType = require( '@stdlib/ndarray/base/unary-input-casting-dtype' );
40-
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
40+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
4141
var getShape = require( '@stdlib/ndarray/shape' ); // note: non-base accessor is intentional due to input ndarrays originating in userland
4242
var ndims = require( '@stdlib/ndarray/ndims' );
4343
var getDType = require( '@stdlib/ndarray/base/dtype' );
@@ -57,27 +57,6 @@ var validate = require( './validate.js' );
5757
var indexOfTypes = require( './index_of_types.js' );
5858

5959

60-
// FUNCTIONS //
61-
62-
/**
63-
* Returns a list of data type enumeration constants.
64-
*
65-
* @private
66-
* @param {Collection} types - list of types
67-
* @returns {IntegerArray} list of data type enumeration constants
68-
*/
69-
function types2enums( types ) {
70-
var out;
71-
var i;
72-
73-
out = [];
74-
for ( i = 0; i < types.length; i++ ) {
75-
out.push( resolveEnum( types[ i ] ) ); // note: we're assuming that `types[i]` is a known data type; otherwise, the resolved enum will be `null`
76-
}
77-
return out;
78-
}
79-
80-
8160
// MAIN //
8261

8362
/**
@@ -183,7 +162,7 @@ function UnaryStrided1dDispatch( table, idtypes, odtypes, policies, options ) {
183162
}
184163
this._table = {
185164
'default': table.default,
186-
'types': ( table.types ) ? types2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
165+
'types': ( table.types ) ? dtypes2enums( table.types ) : [], // note: convert to enums (i.e., integers) to ensure faster comparisons
187166
'fcns': ( table.fcns ) ? copy( table.fcns ) : []
188167
};
189168
if ( this._table.types.length !== this._table.fcns.length*2 ) {
@@ -250,7 +229,6 @@ function UnaryStrided1dDispatch( table, idtypes, odtypes, policies, options ) {
250229
*/
251230
setReadOnly( UnaryStrided1dDispatch.prototype, 'apply', function apply( x ) {
252231
var options;
253-
var dtypes;
254232
var nargs;
255233
var args;
256234
var opts;
@@ -322,8 +300,7 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'apply', function apply( x ) {
322300
xdt = dt;
323301
}
324302
// Resolve the lower-level strided function satisfying the input and output ndarray data types:
325-
dtypes = [ resolveEnum( xdt ), resolveEnum( ydt ) ];
326-
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len
303+
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes2enums( [ xdt, ydt ] ), 1, 0 ); // eslint-disable-line max-len
327304
if ( i >= 0 ) {
328305
f = this._table.fcns[ i ];
329306
} else {
@@ -390,14 +367,14 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'apply', function apply( x ) {
390367
*/
391368
setReadOnly( UnaryStrided1dDispatch.prototype, 'assign', function assign( x ) {
392369
var options;
393-
var dtypes;
394370
var nargs;
395371
var opts;
396372
var args;
397373
var arr;
398374
var err;
399375
var flg;
400376
var xdt;
377+
var ydt;
401378
var tmp;
402379
var dt;
403380
var N;
@@ -461,7 +438,8 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'assign', function assign( x ) {
461438
opts.dims = zeroTo( N );
462439
}
463440
// Determine whether we need to cast the input ndarray...
464-
dt = unaryInputCastingDataType( xdt, getDType( y ), this._policies.casting ); // eslint-disable-line max-len
441+
ydt = getDType( y );
442+
dt = unaryInputCastingDataType( xdt, ydt, this._policies.casting );
465443
if ( xdt !== dt ) {
466444
// TODO: replace the following logic with a call to `ndarray/base/(?maybe-)(cast|convert|copy)` or similar utility
467445
tmp = baseEmpty( dt, getShape( x ), getOrder( x ) );
@@ -470,8 +448,7 @@ setReadOnly( UnaryStrided1dDispatch.prototype, 'assign', function assign( x ) {
470448
xdt = dt;
471449
}
472450
// Resolve the lower-level strided function satisfying the input and output ndarray data types:
473-
dtypes = [ resolveEnum( dt ), resolveEnum( getDType( y ) ) ];
474-
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes, 1, 0 ); // eslint-disable-line max-len
451+
i = indexOfTypes( this._table.fcns.length, 2, this._table.types, 2, 1, 0, dtypes2enums( [ xdt, ydt ] ), 1, 0 ); // eslint-disable-line max-len
475452
if ( i >= 0 ) {
476453
f = this._table.fcns[ i ];
477454
} else {

lib/node_modules/@stdlib/ndarray/dispatch-by/lib/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,10 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
3030
var format = require( '@stdlib/string/format' );
3131
var getDType = require( '@stdlib/ndarray/dtype' );
3232
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
33+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
3334
var indexOfTypes = require( './index_of_types.js' );
3435

3536

36-
// FUNCTIONS //
37-
38-
/**
39-
* Returns a list of data type enumeration constants.
40-
*
41-
* @private
42-
* @param {Collection} types - list of types
43-
* @returns {IntegerArray} list of data type enumeration constants
44-
*/
45-
function types2enums( types ) {
46-
var out;
47-
var i;
48-
49-
out = [];
50-
for ( i = 0; i < types.length; i++ ) {
51-
out.push( resolveEnum( types[ i ] ) );
52-
}
53-
return out;
54-
}
55-
56-
5737
// MAIN //
5838

5939
/**
@@ -151,7 +131,7 @@ function dispatchBy( fcns, types, data, nargs, nin, nout ) {
151131
if ( data && data.length !== nfcns ) {
152132
throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );
153133
}
154-
types = types2enums( types );
134+
types = dtypes2enums( types );
155135
return dispatcher;
156136

157137
/**

lib/node_modules/@stdlib/ndarray/dispatch/lib/main.js

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,10 @@ var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' );
3030
var format = require( '@stdlib/string/format' );
3131
var getDType = require( '@stdlib/ndarray/dtype' );
3232
var resolveEnum = require( '@stdlib/ndarray/base/dtype-resolve-enum' );
33+
var dtypes2enums = require( '@stdlib/ndarray/base/dtypes2enums' );
3334
var indexOfTypes = require( './index_of_types.js' );
3435

3536

36-
// FUNCTIONS //
37-
38-
/**
39-
* Returns a list of data type enumeration constants.
40-
*
41-
* @private
42-
* @param {Collection} types - list of types
43-
* @returns {IntegerArray} list of data type enumeration constants
44-
*/
45-
function types2enums( types ) {
46-
var out;
47-
var i;
48-
49-
out = [];
50-
for ( i = 0; i < types.length; i++ ) {
51-
out.push( resolveEnum( types[ i ] ) );
52-
}
53-
return out;
54-
}
55-
56-
5737
// MAIN //
5838

5939
/**
@@ -150,7 +130,7 @@ function dispatch( fcns, types, data, nargs, nin, nout ) {
150130
if ( data && data.length !== nfcns ) {
151131
throw new Error( 'invalid argument. The third argument must have the same number of elements as the first argument.' );
152132
}
153-
types = types2enums( types );
133+
types = dtypes2enums( types );
154134
return dispatcher;
155135

156136
/**

0 commit comments

Comments
 (0)