Skip to content

Improve reorder_v2 function documentation #218

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 2 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,14 @@ where
temp.into()
}

/// Reorder the array in specified order
/// Reorder the array according to the new specified axes
///
/// The default order of axes in ArrayFire is axis with smallest distance
/// between adjacent elements towards an axis with highest distance between
/// adjacent elements.
/// Exchanges data within an array such that the requested change in axes is
/// satisfied. The linear ordering of data within the array is preserved.
///
/// The default order of axes in ArrayFire is [0 1 2 3] i.e. axis with smallest
/// distance between adjacent elements followed by next smallest distance axis and
/// so on. See [examples](#examples) to have a basic idea of how data is re-ordered.
///
///# Parameters
///
Expand All @@ -537,7 +540,29 @@ where
/// let a = randu::<f32>(Dim4::new(&[5, 3, 1, 1]));
/// let b = reorder_v2(&a, 1, 0, None);
/// print(&a);
///
/// // [5 3 1 1]
/// // 0.8104 0.2990 0.3014
/// // 0.6913 0.2802 0.6938
/// // 0.7821 0.1480 0.3513
/// // 0.3054 0.1330 0.7176
/// // 0.1673 0.4696 0.1181
///
/// print(&b);
/// // [3 5 1 1]
/// // 0.8104 0.6913 0.7821 0.3054 0.1673
/// // 0.2990 0.2802 0.1480 0.1330 0.4696
/// // 0.3014 0.6938 0.3513 0.7176 0.1181
///
/// let c = reorder_v2(&a, 2, 0, Some(vec![1]));
/// print(&c);
///
/// // [1 5 3 1]
/// // 0.8104 0.6913 0.7821 0.3054 0.1673
/// //
/// // 0.2990 0.2802 0.1480 0.1330 0.4696
/// //
/// // 0.3014 0.6938 0.3513 0.7176 0.1181
/// ```
pub fn reorder_v2<T>(
input: &Array<T>,
Expand Down
12 changes: 6 additions & 6 deletions tests/data.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use ::arrayfire::*;
use float_cmp::approx_eq;

#[allow(unused_variables)]
#[test]
fn check_reorder_api() {
let dims = Dim4::new(&[4, 5, 2, 3]);
let A = randu::<f32>(dims);
let a = randu::<f32>(dims);

let transposedA = reorder_v2(&A, 1, 0, None);
let swap_0_2 = reorder_v2(&A, 2, 1, Some(vec![0]));
let swap_1_2 = reorder_v2(&A, 0, 2, Some(vec![1]));
let swap_0_3 = reorder_v2(&A, 3, 1, Some(vec![2, 0]));
let transposed = reorder_v2(&a, 1, 0, None);
let swap_0_2 = reorder_v2(&a, 2, 1, Some(vec![0]));
let swap_1_2 = reorder_v2(&a, 0, 2, Some(vec![1]));
let swap_0_3 = reorder_v2(&a, 3, 1, Some(vec![2, 0]));
}