Skip to content

Commit e7600e8

Browse files
authored
Merge pull request #1009 from rust-ndarray/fix-example-warnings
Fix warnings in examples
2 parents f21c668 + b326ebe commit e7600e8

File tree

11 files changed

+20
-18
lines changed

11 files changed

+20
-18
lines changed

src/arraytraits.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ where
176176
///
177177
/// ```rust
178178
/// use ndarray::{Array, arr1};
179-
/// use std::iter::FromIterator;
180179
///
181180
/// // Either use `from_iter` directly or use `Iterator::collect`.
182181
/// let array = Array::from_iter((0..5).map(|x| x * x));

src/doc/ndarray_for_numpy_users/coord_transform.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
//! for i in 0..nelems {
8484
//! rotated
8585
//! .slice_mut(s![.., .., i])
86-
//! .assign({ &rmat.slice(s![.., .., i]).dot(&eye2d) });
86+
//! .assign(&rmat.slice(s![.., .., i]).dot(&eye2d));
8787
//! }
8888
//! }
8989
//! ```

src/doc/ndarray_for_numpy_users/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
//! ```
180180
//! use ndarray::prelude::*;
181181
//! #
182-
//! # fn main() {}
182+
//! # fn main() { let _ = arr0(1); }
183183
//! ```
184184
//!
185185
//! ## Array creation

src/doc/ndarray_for_numpy_users/rk_step.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
//! (y_new, f_new, error)
105105
//! }
106106
//! #
107-
//! # fn main() {}
107+
//! # fn main() { let _ = rk_step::<fn(_, ArrayView1<'_, _>) -> _>; }
108108
//! ```
109109
//!
110110
//! It's possible to improve the efficiency by doing the following:
@@ -165,7 +165,7 @@
165165
//! (y_new, error)
166166
//! }
167167
//! #
168-
//! # fn main() {}
168+
//! # fn main() { let _ = rk_step::<fn(_, ArrayView1<'_, f64>, ArrayViewMut1<'_, f64>)>; }
169169
//! ```
170170
//!
171171
//! [f64.mul_add()]: https://doc.rust-lang.org/std/primitive.f64.html#method.mul_add

src/impl_constructors.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ where
133133
/// to type `A` fails.
134134
///
135135
/// ```rust
136+
/// # #[cfg(feature = "approx")] {
136137
/// use approx::assert_abs_diff_eq;
137138
/// use ndarray::{Array, arr1};
138139
///
139-
/// # #[cfg(feature = "approx")] {
140140
/// let array = Array::logspace(10.0, 0.0, 3.0, 4);
141141
/// assert_abs_diff_eq!(array, arr1(&[1e0, 1e1, 1e2, 1e3]));
142142
///
@@ -163,11 +163,11 @@ where
163163
/// to type `A` fails.
164164
///
165165
/// ```rust
166+
/// # fn example() -> Option<()> {
167+
/// # #[cfg(feature = "approx")] {
166168
/// use approx::assert_abs_diff_eq;
167169
/// use ndarray::{Array, arr1};
168170
///
169-
/// # fn example() -> Option<()> {
170-
/// # #[cfg(feature = "approx")] {
171171
/// let array = Array::geomspace(1e0, 1e3, 4)?;
172172
/// assert_abs_diff_eq!(array, arr1(&[1e0, 1e1, 1e2, 1e3]), epsilon = 1e-12);
173173
///
@@ -541,8 +541,6 @@ where
541541
///
542542
/// ```
543543
/// use ndarray::{s, Array2};
544-
/// use ndarray::Zip;
545-
/// use ndarray::Axis;
546544
///
547545
/// // Example Task: Let's create a column shifted copy of the input
548546
///
@@ -561,6 +559,8 @@ where
561559
/// b.assume_init()
562560
/// }
563561
/// }
562+
///
563+
/// # let _ = shift_by_two;
564564
/// ```
565565
pub fn uninit<Sh>(shape: Sh) -> ArrayBase<S::MaybeUninit, D>
566566
where

src/impl_methods.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ where
928928
/// Iterator element is `ArrayView1<A>` (1D array view).
929929
///
930930
/// ```
931-
/// use ndarray::{arr3, Axis, arr1};
931+
/// use ndarray::arr3;
932932
///
933933
/// let a = arr3(&[[[ 0, 1, 2], // -- row 0, 0
934934
/// [ 3, 4, 5]], // -- row 0, 1
@@ -996,7 +996,7 @@ where
996996
/// Iterator element is `ArrayView1<A>` (1D array view).
997997
///
998998
/// ```
999-
/// use ndarray::{arr3, Axis, arr1};
999+
/// use ndarray::arr3;
10001000
///
10011001
/// // The generalized columns of a 3D array:
10021002
/// // are directed along the 0th axis: 0 and 6, 1 and 7 and so on...
@@ -1177,7 +1177,6 @@ where
11771177
/// ```
11781178
/// use ndarray::Array;
11791179
/// use ndarray::{arr3, Axis};
1180-
/// use std::iter::FromIterator;
11811180
///
11821181
/// let a = Array::from_iter(0..28).into_shape((2, 7, 2)).unwrap();
11831182
/// let mut iter = a.axis_chunks_iter(Axis(1), 2);
@@ -2397,10 +2396,10 @@ where
23972396
/// Elements are visited in arbitrary order.
23982397
///
23992398
/// ```
2399+
/// # #[cfg(feature = "approx")] {
24002400
/// use approx::assert_abs_diff_eq;
24012401
/// use ndarray::arr2;
24022402
///
2403-
/// # #[cfg(feature = "approx")] {
24042403
/// let mut a = arr2(&[[ 0., 1.],
24052404
/// [-1., 2.]]);
24062405
/// a.mapv_inplace(f32::exp);

src/impl_views/conversions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a, A> ArrayViewMut<'a, A, Ix0> {
9696
///
9797
/// let mut array: Array0<f64> = arr0(5.);
9898
/// let view = array.view_mut();
99-
/// let mut scalar = view.into_scalar();
99+
/// let scalar = view.into_scalar();
100100
/// *scalar = 7.;
101101
/// assert_eq!(scalar, &7.);
102102
/// assert_eq!(array[()], 7.);

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
clippy::while_let_on_iterator, // is not an error
1717
clippy::from_iter_instead_of_collect, // using from_iter is good style
1818
)]
19+
#![doc(test(attr(deny(warnings))))]
20+
#![doc(test(attr(allow(unused_variables))))]
21+
#![doc(test(attr(allow(deprecated))))]
1922
#![cfg_attr(not(feature = "std"), no_std)]
2023

2124
//! The `ndarray` crate provides an *n*-dimensional container for general elements

src/prelude.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
//! and macros that you can import easily as a group.
1313
//!
1414
//! ```
15-
//!
1615
//! use ndarray::prelude::*;
16+
//!
17+
//! # let _ = arr0(1); // use the import
1718
//! ```
1819
1920
#[doc(no_inline)]

src/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ impl_slicenextdim!((), NewAxis, Ix0, Ix1);
741741
/// + v.slice(s![1..-1, 2.. ])
742742
/// + v.slice(s![2.. , 1..-1])
743743
/// }
744-
/// # fn main() { }
744+
/// # fn main() { let _ = laplacian; }
745745
/// ```
746746
///
747747
/// # Negative *step*

0 commit comments

Comments
 (0)