-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use node's util.types.isUint8Array etc for isTypedArray #7181
Use node's util.types.isUint8Array etc for isTypedArray #7181
Conversation
isTypedArray is implemented with `instanceof`, which does not work in jest (jestjs/jest#11864). Instead, use node's builtin `util.types.isUint8Array`, `util.types.isFloat32Array`, etc to perform this check. Fixes tensorflow#7175. This may also address tensorflow#7064, but it does not fix the root cause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 1 approvals obtained (waiting on @Linchenn and @mattsoulanille)
tfjs-core/src/util.ts
line 135 at r1 (raw file):
} export function isTypedArray(a: {}): a is Float32Array|Int32Array|Uint8Array|
please add a test to ensure it fixes the problem for different platforms. thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…exts This change also removes platform_node_test from our normal glob of tests that run on the browser and node and places it in its own Bazel target. Additionally, upgrade @types/node from 12 to 18 to allow importing `node:vm`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review!
Reviewable status: complete! 1 of 1 approvals obtained (waiting on @pyu10055)
tfjs-core/src/util.ts
line 135 at r1 (raw file):
Previously, pyu10055 (Ping Yu) wrote…
please add a test to ensure it fixes the problem for different platforms. thanks
Tests added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 5 of 5 files at r1, 5 of 5 files at r2, all commit messages.
Reviewable status: complete! 2 of 1 approvals obtained
) isTypedArray is implemented with `instanceof`, which does not work in jest (jestjs/jest#11864). Instead, use node's builtin `util.types.isUint8Array`, `util.types.isFloat32Array`, etc to perform this check. Fixes tensorflow#7175. This may also address tensorflow#7064, but it does not fix the root cause.
A new function, `isTypedArray` was added to the `platform` interface by tensorflow#7181 and first published in tfjs-core 4.2.0. This made 4.2.0 incompatible with earlier versions of backends that implemented `platform`, such as node and react-native. This change adds a fallback to the use of `isTypedArray` so earlier versions of platforms that don't implement `isTypedArray` will not throw an error. Note that the behavior may not be perfect, such as when running Jest tests in node. See tensorflow#7175 for more details and upgrade all @tensorflow scoped packages to ^4.2.0 to avoid this. Fixes tensorflow#7273
A new function, `isTypedArray` was added to the `platform` interface by tensorflow#7181 and first published in tfjs-core 4.2.0. This made 4.2.0 incompatible with earlier versions of backends that implemented `platform`, such as node and react-native. This change adds a fallback to the use of `isTypedArray` so earlier versions of platforms that don't implement `isTypedArray` will not throw an error. Note that the fallback behavior may not be perfect, such as when running Jest tests in node. See tensorflow#7175 for more details and upgrade all @tensorflow scoped packages to ^4.2.0 to avoid this. Fixes tensorflow#7273
…#7489) A new function, `isTypedArray` was added to the `platform` interface by #7181 and first published in tfjs-core 4.2.0. This made 4.2.0 incompatible with earlier versions of backends that implemented `platform`, such as node and react-native. This change adds a fallback to the use of `isTypedArray` so earlier versions of platforms that don't implement `isTypedArray` will not throw an error. Note that the fallback behavior may not be perfect, such as when running Jest tests in node. See #7175 for more details and upgrade all @tensorflow scoped packages to ^4.2.0 to avoid this.
isTypedArray is implemented with
instanceof
, which does not work in jest (jestjs/jest#11864). Instead, use node's builtinutil.types.isUint8Array
,util.types.isFloat32Array
, etc to perform this check.Fixes #7175.
This may also address #7064, but it does not fix the root cause.
To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.
This change is