Skip to content

Commit 4fa7af7

Browse files
committed
chore: clean-up
--- 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: passed - 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 ddb1a00 commit 4fa7af7

File tree

7 files changed

+45
-91
lines changed

7 files changed

+45
-91
lines changed

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ limitations under the License.
1818
1919
-->
2020

21-
<!-- eslint-disable id-length -->
22-
2321
# binaryInputCastingDataType
2422

25-
> Resolve the input ndarray casting [data type][@stdlib/ndarray/dtypes] for a binary function.
23+
> Resolve the casting [data type][@stdlib/ndarray/dtypes] for an input ndarray provided to a binary function.
2624
2725
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2826

@@ -46,7 +44,7 @@ var binaryInputCastingDataType = require( '@stdlib/ndarray/base/binary-input-cas
4644

4745
#### binaryInputCastingDataType( idtype1, idtype2, odtype, policy )
4846

49-
Resolves the input ndarray casting [data type][@stdlib/ndarray/dtypes] for a binary function according to a [data type policy][@stdlib/ndarray/input-casting-policies].
47+
Resolves the casting [data type][@stdlib/ndarray/dtypes] for an input ndarray provided to a binary function according to a [data type policy][@stdlib/ndarray/input-casting-policies].
5048

5149
<!-- eslint-disable id-length -->
5250

@@ -57,8 +55,8 @@ var dt = binaryInputCastingDataType( 'int32', 'int32', 'float64', 'promoted' );
5755

5856
The function supports the following parameters:
5957

60-
- **idtype1**: first input ndarray data type.
61-
- **idtype2**: second input ndarray data type.
58+
- **idtype1**: input ndarray data type.
59+
- **idtype2**: additional input ndarray data type.
6260
- **odtype**: output ndarray data type.
6361
- **policy**: input ndarray [casting policy][@stdlib/ndarray/input-casting-policies].
6462

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/docs/repl.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11

2-
{{alias}}( idtype, odtype, policy )
3-
Resolves the input ndarray casting data type for a binary function.
2+
{{alias}}( idtype1, idtype2, odtype, policy )
3+
Resolves the casting data type for an input ndarray provided to a binary
4+
function.
45

56
Parameters
67
----------
78
idtype1: string
8-
First input ndarray data type.
9+
Input ndarray data type.
910

1011
idtype2: string
11-
Second input ndarray data type.
12+
Additional input ndarray data type.
1213

1314
odtype: string
1415
Output ndarray data type.

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/docs/types/index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import { DataType, InputCastingPolicy } from '@stdlib/types/ndarray';
2424

2525
/**
26-
* Resolves the input ndarray casting data type for a binary function.
26+
* Resolves the casting data type for an input ndarray provided to a binary function.
2727
*
28-
* @param idtype1 - first input ndarray data type
29-
* @param idtype2 - second input ndarray data type
28+
* @param idtype1 - input ndarray data type
29+
* @param idtype2 - additional input ndarray data type
3030
* @param odtype - output ndarray data type
3131
* @param policy - input ndarray casting data type policy
3232
* @returns input ndarray casting data type

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Resolve the input ndarray casting data type for a binary function.
22+
* Resolve the casting data type for an input ndarray provided to a binary function.
2323
*
2424
* @module @stdlib/ndarray/base/binary-input-casting-dtype
2525
*

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/lib/main.js

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19-
/* eslint-disable id-length, function-paren-newline */
19+
/* eslint-disable id-length, max-len */
2020

2121
'use strict';
2222

@@ -26,8 +26,9 @@ var isFloatingPointDataType = require( '@stdlib/ndarray/base/assert/is-floating-
2626
var isSignedIntegerDataType = require( '@stdlib/ndarray/base/assert/is-signed-integer-data-type' );
2727
var isUnsignedIntegerDataType = require( '@stdlib/ndarray/base/assert/is-unsigned-integer-data-type' );
2828
var isDataType = require( '@stdlib/ndarray/base/assert/is-data-type' );
29-
var promotionRules = require( '@stdlib/ndarray/promotion-rules' );
29+
var promoteDataTypes = require( '@stdlib/ndarray/base/promote-dtypes' );
3030
var defaults = require( '@stdlib/ndarray/defaults' );
31+
var join = require( '@stdlib/array/base/join' );
3132
var format = require( '@stdlib/string/format' );
3233

3334

@@ -41,10 +42,10 @@ var DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_poin
4142
// MAIN //
4243

4344
/**
44-
* Resolves the input ndarray casting data type for a binary function.
45+
* Resolves the casting data type for an input ndarray provided to a binary function.
4546
*
46-
* @param {string} idtype1 - first input ndarray data type
47-
* @param {string} idtype2 - second input ndarray data type
47+
* @param {string} idtype1 - input ndarray data type
48+
* @param {string} idtype2 - additional input ndarray data type
4849
* @param {string} odtype - output ndarray data type
4950
* @param {string} policy - input ndarray data type casting policy
5051
* @throws {TypeError} fourth argument must be a recognized data type policy
@@ -58,39 +59,30 @@ var DEFAULT_REAL_FLOATING_POINT_DTYPE = defaults.get( 'dtypes.real_floating_poin
5859
function resolve( idtype1, idtype2, odtype, policy ) {
5960
var dt;
6061
if ( policy === 'none' ) {
61-
if (idtype1 !== idtype2) {
62-
throw new Error( format( 'Inputs must match under "none" policy. Got %s and %s.', idtype1, idtype2 ) );
63-
}
62+
// When the policy is 'none', casting behavior is implementation-defined, so we just return the input ndarray data type as is...
6463
return idtype1;
6564
}
6665
if ( policy === 'output' ) {
6766
return odtype;
6867
}
6968
if ( policy === 'promoted' ) {
70-
dt = promotionRules( idtype1, idtype2 );
71-
if ( dt === -1 ) {
72-
throw new Error( format( 'invalid operation. Unable to promote the first input and second input data types. First input data type: %s. Second input data type: %s.', idtype1, idtype2 ) );
73-
}
74-
dt = promotionRules( dt, odtype );
75-
if ( dt === -1 ) {
76-
throw new Error( format( 'invalid operation. Unable to promote the input and output data types. Input data type: %s. Output data type: %s.', dt, odtype ) );
69+
dt = promoteDataTypes( [ idtype1, idtype2, odtype ] );
70+
if ( dt === null ) {
71+
throw new Error( format( 'invalid operation. Unable to promote the input and output data types. Input data types: [%s]. Output data type: %s.', join( [ idtype1, idtype2 ], ', ' ), odtype ) );
7772
}
7873
return dt;
7974
}
8075
if ( policy === 'accumulation' ) {
81-
if ( isFloatingPointDataType( idtype1 ) || isFloatingPointDataType( idtype2 ) || idtype1 === 'generic' || idtype2 === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
82-
return promotionRules(idtype1, idtype2);
76+
// If an input data type is floating-point, allow accumulation in that data type as overflow/underflow is handled naturally as a built-in feature of that data type...
77+
if ( isFloatingPointDataType( idtype1 ) || idtype1 === 'generic' ) { // NOTE: we may want to revisit this in the future for float16/complex32, where the value range is much more limited
78+
return idtype1;
8379
}
84-
// Unless the input data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in smaller range integer data types (e.g., `int8`) are at high risk for overflow, especially for ndarrays containing many elements...
85-
if ( isUnsignedIntegerDataType( idtype1 ) && isUnsignedIntegerDataType( idtype2 ) ) { // eslint-disable-line max-len
86-
return promotionRules(
87-
promotionRules(idtype1, idtype2), DEFAULT_UNSIGNED_INTEGER_DTYPE
88-
);
80+
// Unless an input data type value range is larger than the default un/signed integer data type, accumulate in the default un/signed integer data type, as accumulating in smaller range integer data types (e.g., `int8`) are at high risk for overflow, especially for ndarrays containing many elements...
81+
if ( isUnsignedIntegerDataType( idtype1 ) ) {
82+
return promoteDataTypes( [ idtype1, DEFAULT_UNSIGNED_INTEGER_DTYPE ] );
8983
}
90-
if ( isSignedIntegerDataType( idtype1 ) && isSignedIntegerDataType( idtype2 ) ) { // eslint-disable-line max-len
91-
return promotionRules(
92-
promotionRules(idtype1, idtype2), DEFAULT_SIGNED_INTEGER_DTYPE
93-
);
84+
if ( isSignedIntegerDataType( idtype1 ) ) {
85+
return promoteDataTypes( [ idtype1, DEFAULT_SIGNED_INTEGER_DTYPE ] );
9486
}
9587
// For all other input data types, accumulate in the default real-valued floating-point data type...
9688
return DEFAULT_REAL_FLOATING_POINT_DTYPE;

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/ndarray/base/binary-input-casting-dtype",
33
"version": "0.0.0",
4-
"description": "Resolve the input ndarray casting data type for a binary function.",
4+
"description": "Resolve the casting data type for an input ndarray provided to a binary function.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

lib/node_modules/@stdlib/ndarray/base/binary-input-casting-dtype/test/test.js

Lines changed: 13 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,51 +103,6 @@ tape( 'the function throws an error if provided data types which do not promote
103103
}
104104
});
105105

106-
tape( 'the function throws an error if provided two diffrent data types when the casting policy is "none"', function test( t ) {
107-
var dt1;
108-
var dt2;
109-
var dt3;
110-
var i;
111-
112-
dt1 = [
113-
'float64',
114-
'float32',
115-
'int32',
116-
'uint16',
117-
'generic',
118-
'int8',
119-
'complex64'
120-
];
121-
dt2 = [
122-
'float32',
123-
'float64',
124-
'uint16',
125-
'int32',
126-
'int8',
127-
'complex64',
128-
'generic'
129-
];
130-
dt3 = [
131-
'float64',
132-
'float64',
133-
'float64',
134-
'float64',
135-
'float64',
136-
'float64',
137-
'float64'
138-
];
139-
for ( i = 0; i < dt1.length; i++ ) {
140-
t.throws( badValue( dt1[ i ], dt2[ i ], dt3[ i ] ), Error, 'throws an error when provided '+dt1[ i ]+' and '+dt2[ i ]+' and '+dt3[ i ] );
141-
}
142-
t.end();
143-
144-
function badValue( v1, v2, v3 ) {
145-
return function badValue() {
146-
resolve( v1, v2, v3, 'none' );
147-
};
148-
}
149-
});
150-
151106
tape( 'the function resolves a casting data type (policy=none)', function test( t ) {
152107
var expected;
153108
var dt1;
@@ -281,28 +236,36 @@ tape( 'the function resolves a casting data type (policy=accumulation)', functio
281236
'float32',
282237
'float32',
283238
'float64',
284-
'int16'
239+
'int16',
240+
'generic',
241+
'complex64'
285242
];
286243
dt2 = [
287244
'float16',
288245
'float64',
289246
'uint8c',
290247
'float64',
291-
'int32'
248+
'int32',
249+
'float32',
250+
'float32'
292251
];
293252
dt3 = [
294253
'int8',
295254
'float64',
296255
'float16',
297256
'int16',
298-
'int32'
257+
'int32',
258+
'int32',
259+
'int16'
299260
];
300261
expected = [
301262
'float16',
302-
'float64',
263+
'float32',
303264
'float32',
304265
'float64',
305-
'int32'
266+
'int32',
267+
'generic',
268+
'complex64'
306269
];
307270

308271
for ( i = 0; i < dt1.length; i++ ) {

0 commit comments

Comments
 (0)