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

export transpose! and ctranspose! #7814

Merged
merged 2 commits into from
Nov 11, 2014
Merged

Conversation

Jutho
Copy link
Contributor

@Jutho Jutho commented Aug 2, 2014

This PR proposes to export transpose! and ctranspose!. When I was modified these functions a while ago ( #6690 ), I decided not to export them because the original transpose! was also not exported. However, given that a lot of the mutating methods are exported, it would make sense to export these as well.

If you agree to merge (before or after 0.3), I can also add them to the docs.

@JeffBezanson
Copy link
Member

Maybe there should be an error if the two arguments are ===, since the function doesn't work in that case?

@ivarne
Copy link
Member

ivarne commented Aug 2, 2014

Can't multiple arrays reference the same memory, so that you actually need to compare the pointers of both start and end of both arrays, to ensure they don't overlap?

@Jutho
Copy link
Contributor Author

Jutho commented Aug 2, 2014

These are valid points. Is this correctly checked for all user exposed functions? I never looked into other examples, aside from permutedims!, where I know for certain that no such checks are in place. I always assumed that it was the user's responsibility to know what he was doing when using the ! functions. What if two strided arrays overlap, but in such a way that they do not reference the same memory locations? Suppose that for a 2N x 2N matrix you want to do transpose!(slice(A,1:2:2N,1:2:2N),slice(A,2:2:2N,2:2:2N)). Should this be allowed? If so, then it becomes pretty hard to check whether something is a valid operation or not. Maybe it's not too bad for transpose!, but for permutedims! this might be more difficult, since I don't think there is any simplification over comparing all memory locations.

@JeffBezanson
Copy link
Member

I only brought this up since I tried transpose!(A) to see if I could transpose a single array in place. Seeing it only accepted 2 arguments, I tried transpose!(A,A).

@Jutho
Copy link
Contributor Author

Jutho commented Aug 2, 2014

That would indeed be problematic with the current implementation. In place transposition is apparently a hard problem for non-square matrices. Note that this even changes the size of the matrix, which is something that you don’t typically expect for mutating operations on arrays.

On 02 Aug 2014, at 19:41, Jeff Bezanson [email protected] wrote:

I only brought this up since I tried transpose!(A) to see if I could transpose a single array in place. Seeing it only accepted 2 arguments, I tried transpose!(A,A).


Reply to this email directly or view it on GitHub.

@Jutho
Copy link
Contributor Author

Jutho commented Aug 2, 2014

@JeffBezanson
Copy link
Member

I agree you can only reasonably do it for square matrices, but this is just an example of something somebody might try.

@Jutho
Copy link
Contributor Author

Jutho commented Aug 2, 2014

That’s true. I am totally open on how to deal with this. Only throw an error for this specific case explicitly, and warn against other potential issues in the docs. Or don’t check at all and warn in the docs.

On 02 Aug 2014, at 20:17, Jeff Bezanson [email protected] wrote:

I agree you can only reasonably do it for square matrices, but this is just an example of something somebody might try.


Reply to this email directly or view it on GitHub.

@jiahao jiahao force-pushed the master branch 3 times, most recently from 6c7c7e3 to 1a4c02f Compare October 11, 2014 22:06
@ViralBShah
Copy link
Member

I think we can merge this once the check is implemented. Throw an error for the specific case and warn against potential issues in docs seems like a reasonable solution.

@Jutho Jutho force-pushed the jh/exporttranspose! branch from 4f4112a to 1af23bb Compare November 6, 2014 22:58
@Jutho
Copy link
Contributor Author

Jutho commented Nov 6, 2014

I rebased and added documentation, with explicit warning regarding unexpected results if the arrays overlap.

Regarding adding the check for the specific case where the two arguments are ===. I am happy to add them, but should I then be consistent, e.g. also add them in permutedims!, and maybe even copy! (although that's probably harmless), and the A_mul_B! family, and ...

There are many places where you can basically trigger this kind of problem. I am not sure whether we need to start adding checks now. If you use the mutating methods, aren't you supposed to know what you are doing.

@andreasnoack
Copy link
Member

I don't think that these checks are necessary. If you are using the ! versions, you are supposed to know what you are doing.

@ViralBShah
Copy link
Member

That's a fair point. Let's go ahead and merge.

@Jutho Jutho force-pushed the jh/exporttranspose! branch 2 times, most recently from 4790069 to 9499bb0 Compare November 8, 2014 20:21
@Jutho
Copy link
Contributor Author

Jutho commented Nov 9, 2014

I've rebased and squashed the commits. If no more comments, I will merge tomorrow.

@ViralBShah
Copy link
Member

I think the sparse transpose defines these in reverse order. Should we make it consistent?

@ViralBShah
Copy link
Member

Also, I think these are useful to export, since there are cases where you can significantly avoid memory allocation.

@Jutho
Copy link
Contributor Author

Jutho commented Nov 10, 2014

I think the sparse transpose defines these in reverse order. Should we make it consistent?

There doesn’t seem to be a transpose! for sparse matrices. I am not sure if that is what you mean?

@ViralBShah
Copy link
Member

It exists. Look in csparse.jl.

@Jutho
Copy link
Contributor Author

Jutho commented Nov 10, 2014

Now I see. I just tried with @which Base.transpose!(a,b) where a and b are two sparse matrices. The problem with this is that the transpose! method for sparse is completely disconnected (i.e. different function) from Base.transpose!. So that should also be fixed. I'll take a stab at it tonight.

I guess the argument of the sparse matrices is in conflict with the typical convention of the first argument being the one that is modified / used as output (e.g. in copy!, permutedims!, ...)

@ViralBShah
Copy link
Member

That's right. It needs to be updated with the new convention.

@Jutho Jutho force-pushed the jh/exporttranspose! branch from 9499bb0 to ba1f731 Compare November 11, 2014 09:23
@Jutho
Copy link
Contributor Author

Jutho commented Nov 11, 2014

I've added the sparse functionality. Should I squash those two commits?

@ViralBShah
Copy link
Member

I think it is better to have the commits the way they are, and a separate commit for the sparse transpose for future reference.

@Jutho
Copy link
Contributor Author

Jutho commented Nov 11, 2014

That's what I thought.

Jutho added a commit that referenced this pull request Nov 11, 2014
export transpose! and ctranspose!
@Jutho Jutho merged commit 4837804 into JuliaLang:master Nov 11, 2014
@Jutho
Copy link
Contributor Author

Jutho commented Nov 18, 2014

I think this is ok for @JuliaBackports

@tkelman
Copy link
Contributor

tkelman commented Nov 18, 2014

thanks - second commit here doesn't apply cleanly, see conflict diff at https://gist.github.com/aeb8cc230b506e921a84
what's the best resolution there?

@tkelman
Copy link
Contributor

tkelman commented Nov 18, 2014

there was a different PR for sparse in-place sorting, that I guess this one depends on due to the conflicts. maybe wait until after 0.3.3, look at backporting that one, then come back to this.

@Jutho
Copy link
Contributor Author

Jutho commented Nov 18, 2014

That's fine with me. I know very little about the sparse functionality, I never use it and never really looked into it.

@JeffBezanson
Copy link
Member

I'm not sure adding new exports really needs to be or should be backported.

@Jutho
Copy link
Contributor Author

Jutho commented Nov 18, 2014

Also fine, no preference here.

@ViralBShah
Copy link
Member

I think this one does not need backporting - see my other comment on not backporting the sparse multiplication update. Taking off the backport label.

@Jutho Jutho deleted the jh/exporttranspose! branch January 8, 2015 08:58
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.

6 participants