-
Notifications
You must be signed in to change notification settings - Fork 28
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
Improve performance of rotate function #33
Comments
We were thinking that a better implementation would probably need to reorder the grid, rather than creating a new one. The problem is that it implies an in-place transpose. We already tried the "follow-the-cycle" algorithm, but while it is O(n) in time and memory just like the currently implemented transpose, it is also half as fast. The other option we can explore would be to support column-major grids. Indeed, a transposed row-major grid is the same grid in column-major order. I see two ways of doing that, but they share some issues. The first way would be to include a The second way would be to add a second generic type on the grid. I think a snippet will be more understandable than a long description: trait GridOrder {
type Counterpart: GridOrder;
fn counterpart_order(self) -> Self::Counterpart;
fn index_in_grid<T>(grid: &Grid<T, Self>, row: usize, col: usize) -> usize;
}
struct RowMajor;
struct ColumnMajor;
enum DynamicOrder {
RowMajor,
ColumnMajor,
}
impl GridOrder for RowMajor { ... }
impl GridOrder for ColumnMajor { ... }
impl GridOrder for DynamicOrder { ... }
struct Grid<T, O = RowMajor> { ... } The signature for transpose would then look like In both solutions, it would introduce an issue with the I can take the time to experiment with either or both solutions, but I would like your input before I commit to this effort. Does this make any sense to you ? Is it worthwhile to pursue ? |
Thanks for taking the time. Interesting that transpose is a change in row to column major order. Didn't know that. I think it would be great if What I don't understand is what you mean with?
Right now all operations are alraedy performed on a 1D datastruct internaly. That is also the reason why Loosing the So it does make a lot of sense to me to also support column-major orders for the |
Yes, it will be quite the task, but I'm willing to give it a shot! Luckily I have time on my hands this summer.
Yes I know, but the methods do take 2D coordinates, and you have to transform them to a 1D index. If we embed a
In my opinion, the exposed API should be as independent from the grid order as possible. Switching from I will start with the simple solution, and start a MR in the following days, on which we will be able to discuss specifics. |
@Shir0kamii @becheran Not wanting to blow my own trumpet, but I have written performant |
See discussion in #32
The text was updated successfully, but these errors were encountered: