Skip to content

Add note about memory layout in .to_owned() docs #442

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

Merged
merged 1 commit into from
May 4, 2018

Conversation

jturner314
Copy link
Member

Questions:

  • Is this the right place to put this?
  • Can we improve upon these example implementations? They're pretty verbose.

@ExpHP
Copy link
Contributor

ExpHP commented Apr 27, 2018

My feelings:

  • to_owned is one of the places I looked; I think it is a good location
    • This location has the advantage of also being to describe Fortran layout, which wouldn't work so well on is_standard_layout
  • I'm also glad that it includes the search phrase "standard layout"

I would consider #441 to be solved by this.

/// If you need a particular layout, you can allocate a new array with the
/// desired memory layout and [`.assign()`](#method.assign) the data.
/// Alternatively, you can collect an iterator, like this for a result in
/// standard layout:
Copy link
Member

Choose a reason for hiding this comment

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

This can be fine as a contract, but I don't really agree with it. The layout of the output should be the same as that of the input, if possible. Then we restrict and say it's only possible if the input is contiguous (which is more or less true). Then yes, that's not entirely correct with the current implementation, since not all contiguous arrays are covered right now (but most..).

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, how about

If the input array is contiguous and its strides are positive, then the output array will have the same memory layout. Otherwise, the layout of the output array is unspecified. If you need a particular layout…

As far as I can tell, this description matches the current implementation. Once we add support for negative strides in .is_contiguous(), we can remove the "strides are positive" constraint.

Copy link
Member

Choose a reason for hiding this comment

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

Yes that's good

@jturner314 jturner314 force-pushed the more-to-owned-docs branch from c39954c to 8c003b0 Compare May 4, 2018 02:25
@jturner314 jturner314 merged commit 98d20ef into rust-ndarray:master May 4, 2018
@jturner314 jturner314 deleted the more-to-owned-docs branch May 4, 2018 02:42
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.

3 participants