Skip to content

How to transpose? #8

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

Closed
grothesque opened this issue Nov 27, 2024 · 12 comments
Closed

How to transpose? #8

grothesque opened this issue Nov 27, 2024 · 12 comments

Comments

@grothesque
Copy link

In current mdarray, is it possible to perform a (generalized) transpose operation, i.e. change the order of dimensions without copying the data?

Since a strided layout is supported this should be technically possible.

@fre-hu
Copy link
Owner

fre-hu commented Nov 29, 2024

See the reorder, reorder_mut and into_reordered methods. Are they what you mean?

@grothesque
Copy link
Author

Ah, I didn't find this one since I was searching for "Strided" on the documentation page for Slice.

Yes, this solves this provides transpose, but actually for my own project I need general reordering of dimensions. Technically this is possible with mdarray, right? Is it just a matter of writing a function, or would that need some reorganization of types as well?

@fre-hu
Copy link
Owner

fre-hu commented Nov 29, 2024

There are functions for general permutations also (permute/permut_mut/into_permuted). Like the view functions they are implemented for fixed rank, so you might have issues with dynamic rank. Maybe the interface for all of these should be updated in some way.

Yes, you can also write a standalone function that uses View::new_unchecked with the pointer and a new mapping from StridedMapping::new. For dynamic rank you don't need any reorganization of types.

@grothesque
Copy link
Author

Thanks!

IMHO the view/permute interface should be either (eventually) updated, or the dynamic rank removed. It feels incomplete in the current state. See #7 for my thoughts. No idea if/how C++ mdarray handles the dynamic rank case.

(BTW I hate to use the term rank for number of dimensions, because for me the rank of a matrix is something different. But I see that C++ mdarray uses the same term, and also it's compact.)

@fre-hu
Copy link
Owner

fre-hu commented Dec 5, 2024

I've made one more commit where the permutation can be dynamic, and also axis arguments in other functions. This simplifies the typical case with dynamic dimensions and is more aligned with ndarray. There are also axis index functions for simple views, which work with dynamic rank. Hopefully this should improve useability.

C++ mdarray does not support dynamic rank.

@grothesque
Copy link
Author

grothesque commented Jan 13, 2025

With the updated permute this one is solved, isn't it? (I tried to test permutations of DynRank-arrays with many dimensions, but got stuck.) Edit: It works, only that I don't know how to use static arrays as shapes.

@fre-hu
Copy link
Owner

fre-hu commented Jan 13, 2025

Yes I think so, I will close it. I'm not sure what you mean with static arrays, but the permutation must be an IntoShape (i.e Dim tuple, [usize; N], &[usize] or similar).

@fre-hu fre-hu closed this as completed Jan 18, 2025
@grothesque
Copy link
Author

I'm not sure what you mean with static arrays

I meant what you answered in #6 (comment). Thanks.

@grothesque
Copy link
Author

Having used reorder for a while, I cannot get used to the name. To me, “reorder” is a synonym of “permute”, while the method reorder performs a very specific reordering/permutation.

How about renaming reorder to transpose? This naming might be not perfectly adequate when there are more than 2 dimensions, but since there is no well-known multi-dimensional generalization of the transpose operation, I think that would be OK. In terms of precedent, at least NumPy works like this.

If “transpose” is not acceptable, how about “reverse_axes”, or “reverse_dims”, or something like that? Or just “reverse”, but IMHO that could be confused with reversing the order of entries inside the array. (I do think that “transpose” is clearer, though.)

If it has to remain reorder, I suggest to at least clarify the documentation string which currently says: “Returns a reordered array view of the array slice.”

@fre-hu
Copy link
Owner

fre-hu commented Apr 6, 2025

I agree, reorder is not so good name.

I was unsure how to define the transposition operation, but it is probably best to follow the convention in Numpy and rename reorder to transpose.

@fre-hu
Copy link
Owner

fre-hu commented Apr 27, 2025

Fixed, see latest commit.

@grothesque
Copy link
Author

Thanks!

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

No branches or pull requests

2 participants