fix SDL rule (#6464)

This commit is contained in:
Yulong Wang 2021-01-27 15:32:45 -08:00 committed by GitHub
parent 1ce1a51d46
commit ed1ebd2e21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -87,20 +87,20 @@ export class Tensor implements TensorInterface {
data = arg1;
} else {
// numeric tensor
const constructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
if (constructor === undefined) {
const typedArrayConstructor = NUMERIC_TENSOR_TYPE_TO_TYPEDARRAY_MAP.get(arg0);
if (typedArrayConstructor === undefined) {
throw new TypeError(`Unknown tensor type: ${arg0}.`);
}
if (Array.isArray(arg1)) {
// use 'as any' here because TypeScript's check on type of 'SupportedTypedArrayConstructors.from()' produces
// incorrect results.
// 'constructor' should be one of the typed array prototype objects.
// 'typedArrayConstructor' should be one of the typed array prototype objects.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
data = (constructor as any).from(arg1);
} else if (arg1 instanceof constructor) {
data = (typedArrayConstructor as any).from(arg1);
} else if (arg1 instanceof typedArrayConstructor) {
data = arg1;
} else {
throw new TypeError(`A ${type} tensor's data must be type of ${constructor}`);
throw new TypeError(`A ${type} tensor's data must be type of ${typedArrayConstructor}`);
}
}
} else {