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

Update chex.assert_type to check concrete types instead of just asserting that the type is a floating/integer sub-type. #333

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

copybara-service[bot]
Copy link

Update chex.assert_type to check concrete types instead of just asserting that the type is a floating/integer sub-type.

Previously, assert_type would only check that the input was of the same parent type. For example:

x = np.ones((1,), dtype=np.float32)
chex.assert_type(x, np.float64)  # Succeeds
chex.assert_type(x, np.int32)  # Fails.

Instead, if a concrete dtype is provided we check that the input has the same type. If float or np.floating is provided, we continue to only assert that the input is the same parent.

x = np.ones((1,), dtype=np.float32)
chex.assert_type(x, np.float64) # Fails
chex.assert_type(x, float) # Succeeds.

@copybara-service copybara-service bot force-pushed the test_607102995 branch 3 times, most recently from 65d620f to b63c512 Compare February 22, 2024 09:04
…erting that the type is a floating/integer sub-type.

Previously, `assert_type` would only check that the input was of the same parent type. For example:
```
x = np.ones((1,), dtype=np.float32)
chex.assert_type(x, np.float64)  # Succeeds
chex.assert_type(x, np.int32)  # Fails.
```

Instead, if a concrete dtype is provided we check that the input has the same type. If `float` or `np.floating` is provided, we continue to only assert that the input is the same parent.

```
x = np.ones((1,), dtype=np.float32)
chex.assert_type(x, np.float64) # Fails
chex.assert_type(x, float) # Succeeds.
```
PiperOrigin-RevId: 609283182
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.

1 participant