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

Fix sort-axis example, add test to confirm original error and resolution #916

Merged
merged 1 commit into from
Feb 11, 2021

Conversation

dam5h
Copy link
Contributor

@dam5h dam5h commented Feb 9, 2021

Noticed a sorting issue when using this example code in my application. After building a couple tests and sharing with @bluss , he determined that the perm_i and i vars were swapped in the Zip comprehension. Once fixed, a single test case was left which would have caught the original failure.

@dam5h dam5h mentioned this pull request Feb 9, 2021
examples/sort-axis.rs Outdated Show resolved Hide resolved
examples/sort-axis.rs Outdated Show resolved Hide resolved
@bluss
Copy link
Member

bluss commented Feb 9, 2021

I pushed (a fix to your branch), but I'd prefer if real tests were added before merge - we can find a shorter example that was wrong before. And we'd need to fix CI so that it actually tests the examples.

moved_elements += 1;
});
}
Zip::from(&perm.indices)
Copy link
Member

@bluss bluss Feb 9, 2021

Choose a reason for hiding this comment

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

tip, we can use slices just fine in Zip.

All that was needed for the fix was to swap perm_i and i, but I saw this change as an improvement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the tip, I haven't used Zip much but should start. I noticed this change being beyond the index swap.

@dam5h
Copy link
Contributor Author

dam5h commented Feb 10, 2021

I pushed, but I'd prefer if real tests were added before merge - we can find a shorter example that was wrong before. And we'd need to fix CI so that it actually tests the examples.

Ah, I made a comment above about the test being outdated now (before seeing this one), I will trim up the file to reproduce the original error and amend my last commit. Also added --examples to the test script.

@bluss
Copy link
Member

bluss commented Feb 11, 2021

Can we squash together the commits? In particular so that the big array file disappears from the history-to-merge. Thanks :)


let perm = a.sort_axis_by(Axis(0), |i, j| a[[i, 0]] < a[[j, 0]]);
let b = a.permute_axis(Axis(0), &perm);
assert_eq!(b.row(0), array![75600.0927734375, 0.00011850080901105835]);
Copy link
Member

Choose a reason for hiding this comment

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

sorry for the nitpick but sorting is best by asserting that every element is <= its predecessor (and some way of checking the other elements in the same row are moved correctly).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed! I'll do this and then squash them up.

also replaced outer iteration with zip directly since it takes slices.
@bluss
Copy link
Member

bluss commented Feb 11, 2021

Don't forget to update pr description & title before merge for the new state of the PR. Thanks for this

@bluss bluss marked this pull request as ready for review February 11, 2021 09:52
@dam5h dam5h changed the title investigating issue where large array is not properly sorted by sort-… Fix sort-axis example, add test to confirm original error and resolution Feb 11, 2021
@bluss
Copy link
Member

bluss commented Feb 11, 2021

Thanks for this!

@bluss bluss merged commit a6fe82f into rust-ndarray:master Feb 11, 2021
@dam5h
Copy link
Contributor Author

dam5h commented Feb 11, 2021

Sure, thanks for your help and the library! Used ndarray for my first non-toy rust app, took a little understanding at first but its a great library!

@dam5h dam5h deleted the permute-axis-not-sorting branch February 11, 2021 16:19
Euphrasiologist pushed a commit to Euphrasiologist/oxygraphis that referenced this pull request Sep 12, 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.

2 participants