Skip to content

Commit

Permalink
Merge pull request #1044 from jturner314/concatenate-macro-optional-c…
Browse files Browse the repository at this point in the history
…omma

Allow trailing comma in stack and concatenate macros
  • Loading branch information
bluss authored Oct 28, 2021
2 parents bd3aa27 + f9b8d78 commit 005efdc
Showing 1 changed file with 43 additions and 18 deletions.
61 changes: 43 additions & 18 deletions src/stacking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,22 +192,39 @@ where
///
/// # fn main() {
///
/// let a = arr2(&[[2., 2.],
/// [3., 3.]]);
/// assert!(
/// stack![Axis(0), a, a]
/// == arr3(&[[[2., 2.],
/// [3., 3.]],
/// [[2., 2.],
/// [3., 3.]]])
/// let a = arr2(&[[1., 2.],
/// [3., 4.]]);
/// assert_eq!(
/// stack![Axis(0), a, a],
/// arr3(&[[[1., 2.],
/// [3., 4.]],
/// [[1., 2.],
/// [3., 4.]]]),
/// );
/// assert_eq!(
/// stack![Axis(1), a, a,],
/// arr3(&[[[1., 2.],
/// [1., 2.]],
/// [[3., 4.],
/// [3., 4.]]]),
/// );
/// assert_eq!(
/// stack![Axis(2), a, a],
/// arr3(&[[[1., 1.],
/// [2., 2.]],
/// [[3., 3.],
/// [4., 4.]]]),
/// );
/// # }
/// ```
#[macro_export]
macro_rules! stack {
($axis:expr, $( $array:expr ),+ ,) => {
$crate::stack!($axis, $($array),+)
};
($axis:expr, $( $array:expr ),+ ) => {
$crate::stack($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap()
}
};
}

/// Concatenate arrays along the given axis.
Expand All @@ -226,22 +243,30 @@ macro_rules! stack {
///
/// # fn main() {
///
/// let a = arr2(&[[2., 2.],
/// [3., 3.]]);
/// assert!(
/// concatenate![Axis(0), a, a]
/// == arr2(&[[2., 2.],
/// [3., 3.],
/// [2., 2.],
/// [3., 3.]])
/// let a = arr2(&[[1., 2.],
/// [3., 4.]]);
/// assert_eq!(
/// concatenate![Axis(0), a, a],
/// arr2(&[[1., 2.],
/// [3., 4.],
/// [1., 2.],
/// [3., 4.]]),
/// );
/// assert_eq!(
/// concatenate![Axis(1), a, a,],
/// arr2(&[[1., 2., 1., 2.],
/// [3., 4., 3., 4.]]),
/// );
/// # }
/// ```
#[macro_export]
macro_rules! concatenate {
($axis:expr, $( $array:expr ),+ ,) => {
$crate::concatenate!($axis, $($array),+)
};
($axis:expr, $( $array:expr ),+ ) => {
$crate::concatenate($axis, &[ $($crate::ArrayView::from(&$array) ),* ]).unwrap()
}
};
}

/// Stack arrays along the new axis.
Expand Down

0 comments on commit 005efdc

Please sign in to comment.