Skip to content

Commit 2816113

Browse files
committed
Simplify trait bounds
1 parent d5e7f67 commit 2816113

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

src/stacking.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ use crate::imp_prelude::*;
3333
/// [3., 3.]]))
3434
/// );
3535
/// ```
36-
pub fn concatenate<S, D, A>(axis: Axis, arrays: &[ArrayBase<S, D, A>]) -> Result<Array<A, D>, ShapeError>
36+
pub fn concatenate<S, D>(axis: Axis, arrays: &[ArrayBase<S, D>]) -> Result<Array<S::Elem, D>, ShapeError>
3737
where
38-
S: Data<Elem = A>,
39-
A: Clone,
38+
S: Data,
39+
S::Elem: Clone,
4040
D: RemoveAxis,
4141
{
4242
if arrays.is_empty() {
@@ -97,12 +97,11 @@ where
9797
/// );
9898
/// # }
9999
/// ```
100-
pub fn stack<S, D, A>(axis: Axis, arrays: &[ArrayBase<S, D, A>]) -> Result<Array<A, D::Larger>, ShapeError>
100+
pub fn stack<S, D>(axis: Axis, arrays: &[ArrayBase<S, D>]) -> Result<Array<S::Elem, D::Larger>, ShapeError>
101101
where
102-
S: Data<Elem = A>,
103-
A: Clone,
102+
S: Data,
103+
S::Elem: Clone,
104104
D: Dimension,
105-
D::Larger: RemoveAxis,
106105
{
107106
if arrays.is_empty() {
108107
return Err(from_kind(ErrorKind::Unsupported));

tests/stacking.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
11
use ndarray::{arr2, arr3, aview1, aview2, concatenate, stack, Array2, Axis, ErrorKind, Ix1, ViewRepr};
22

33
#[test]
4-
fn concatenating()
5-
{
4+
fn concatenating() {
65
let a = arr2(&[[2., 2.], [3., 3.]]);
76
let b = ndarray::concatenate(Axis(0), &[a.view(), a.view()]).unwrap();
87
assert_eq!(b, arr2(&[[2., 2.], [3., 3.], [2., 2.], [3., 3.]]));
98

109
let c = concatenate![Axis(0), a, b];
11-
assert_eq!(
12-
c,
13-
arr2(&[[2., 2.], [3., 3.], [2., 2.], [3., 3.], [2., 2.], [3., 3.]])
14-
);
10+
assert_eq!(c, arr2(&[[2., 2.], [3., 3.], [2., 2.], [3., 3.], [2., 2.], [3., 3.]]));
1511

1612
let d = concatenate![Axis(0), a.row(0), &[9., 9.]];
1713
assert_eq!(d, aview1(&[2., 2., 9., 9.]));
1814

1915
let d = concatenate![Axis(1), a.row(0).insert_axis(Axis(1)), aview1(&[9., 9.]).insert_axis(Axis(1))];
20-
assert_eq!(d, aview2(&[[2., 9.],
21-
[2., 9.]]));
16+
assert_eq!(d, aview2(&[[2., 9.], [2., 9.]]));
2217

2318
let d = concatenate![Axis(0), a.row(0).insert_axis(Axis(1)), aview1(&[9., 9.]).insert_axis(Axis(1))];
2419
assert_eq!(d, aview2(&[[2.], [2.], [9.], [9.]]));
@@ -29,13 +24,12 @@ fn concatenating()
2924
let res = ndarray::concatenate(Axis(2), &[a.view(), c.view()]);
3025
assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds);
3126

32-
let res: Result<Array2<f64>, _> = ndarray::concatenate::<ViewRepr<&f64>, _, _>(Axis(0), &[]);
27+
let res: Result<Array2<f64>, _> = ndarray::concatenate::<ViewRepr<&f64>, _>(Axis(0), &[]);
3328
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
3429
}
3530

3631
#[test]
37-
fn stacking()
38-
{
32+
fn stacking() {
3933
let a = arr2(&[[2., 2.], [3., 3.]]);
4034
let b = ndarray::stack(Axis(0), &[a.view(), a.view()]).unwrap();
4135
assert_eq!(b, arr3(&[[[2., 2.], [3., 3.]], [[2., 2.], [3., 3.]]]));
@@ -50,6 +44,6 @@ fn stacking()
5044
let res = ndarray::stack(Axis(3), &[a.view(), a.view()]);
5145
assert_eq!(res.unwrap_err().kind(), ErrorKind::OutOfBounds);
5246

53-
let res: Result<Array2<f64>, _> = ndarray::stack::<ViewRepr<&f64>, Ix1, _>(Axis(0), &[]);
47+
let res: Result<Array2<f64>, _> = ndarray::stack::<ViewRepr<&f64>, Ix1>(Axis(0), &[]);
5448
assert_eq!(res.unwrap_err().kind(), ErrorKind::Unsupported);
5549
}

0 commit comments

Comments
 (0)