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

TST Add checks for contiguity of loaded numpy arrays #160

Merged

Conversation

BenjaminBossan
Copy link
Collaborator

Resolves #149

If an array is at least 2d, test if the contiguity is preserved. For some sklearn models, there are attributes whose contiguity changes after loading (they are curiously neither C nor F contiguous). Those are all 1d, however (sometimes after squeezing), so contiguity should not be an issue.

There is a known gap with 2d (or higher) object arrays, where contiguity is not always preserved. Since those don't seem to occur in sklearn, we don't fix that error for now.

If an array has at least 2d, test if the contiguity is preserved. For
some sklearn models, there are attributes whose contiguity changes after
loading (they are curiously neither C nor F contiguous). Those are all
1d, however (sometimes after squeezing), so contiguity should not be an
issue.

There is a known gap with 2d (or higher) object arrays, where contiguity
is not always preserved. Since those don't seem to occur in sklearn, we
don't fix that error for now.
@BenjaminBossan
Copy link
Collaborator Author

Ready for review @skops-dev/maintainers

Comment on lines +280 to +282
if val1.squeeze().ndim > 1:
assert val1.flags["C_CONTIGUOUS"] is val2.flags["C_CONTIGUOUS"]
assert val1.flags["F_CONTIGUOUS"] is val2.flags["F_CONTIGUOUS"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and all the tests pass! nice!

@adrinjalali adrinjalali changed the title Add checks for contiguity of loaded numpy arrays TST Add checks for contiguity of loaded numpy arrays Sep 30, 2022
@adrinjalali adrinjalali merged commit be34ea2 into skops-dev:main Sep 30, 2022
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.

Secure persistence: Contiguity of arrays may change after loading
2 participants