Skip to content
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

Merged
merged 4 commits into from
Dec 16, 2022

Conversation

mattsoulanille
Copy link
Member

@mattsoulanille mattsoulanille commented Dec 15, 2022

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 #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 Reviewable

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.
@mattsoulanille mattsoulanille marked this pull request as ready for review December 15, 2022 19:32
Copy link
Collaborator

@pyu10055 pyu10055 left a 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

Copy link
Collaborator

@Linchenn Linchenn left a 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`.
Copy link
Member Author

@mattsoulanille mattsoulanille left a 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: :shipit: 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

Copy link
Collaborator

@pyu10055 pyu10055 left a 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: :shipit: complete! 2 of 1 approvals obtained

@mattsoulanille mattsoulanille merged commit ae902e5 into tensorflow:master Dec 16, 2022
Linchenn pushed a commit to Linchenn/tfjs that referenced this pull request Jan 9, 2023
)

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.
mattsoulanille added a commit to mattsoulanille/tfjs that referenced this pull request Mar 16, 2023
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
mattsoulanille added a commit to mattsoulanille/tfjs that referenced this pull request Mar 16, 2023
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
mattsoulanille added a commit that referenced this pull request Mar 21, 2023
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tfjs raises an error in Jest(unit testing) environment and Node.js runtime
3 participants