Skip to content

Commit 1daa82f

Browse files
authored
docs/tests: fix rustdoc links and appease clippy strict lints (#1576)
Tighten linting; fix rustdoc warnings across feature gates I continued using stricter linting and found several odd cases in tests and examples, along with rustdoc warnings triggered by feature-gated items. This commit cleans up those warnings by: - adjusting tests to avoid clippy false positives under -D warnings - removing unused generics and ambiguous empty vec initializers - fixing rustdoc links via feature-gated doc attributes rather than linking to non-exported items All tests are still passing. Clippy still warns about the use of `1..-1` as an empty range; this appears intentional in ndarray slicing semantics, so I’ve left it unchanged for now. Please review the rustdoc changes that rely on feature-gated documentation.
1 parent f6f06ce commit 1daa82f

File tree

8 files changed

+88
-77
lines changed

8 files changed

+88
-77
lines changed

src/doc/crate_feature_flags.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414
//! ## `serde`
1515
//! - Enables serialization support for serde 1.x
1616
//!
17-
//! ## `rayon`
18-
//! - Enables parallel iterators, parallelized methods, the [`parallel`] module and [`par_azip!`].
19-
//! - Implies std
17+
#![cfg_attr(
18+
not(feature = "rayon"),
19+
doc = "//! ## `rayon`\n//! - Enables parallel iterators, parallelized methods, and the `par_azip!` macro.\n//! - Implies std\n"
20+
)]
21+
#![cfg_attr(
22+
feature = "rayon",
23+
doc = "//! ## `rayon`\n//! - Enables parallel iterators, parallelized methods, the [`crate::parallel`] module and [`crate::parallel::par_azip`].\n//! - Implies std\n"
24+
)]
2025
//!
2126
//! ## `approx`
2227
//! - Enables implementations of traits of the [`approx`] crate.
@@ -28,8 +33,3 @@
2833
//!
2934
//! ## `matrixmultiply-threading`
3035
//! - Enable the ``threading`` feature in the matrixmultiply package
31-
//!
32-
//! [`parallel`]: crate::parallel
33-
34-
#[cfg(doc)]
35-
use crate::parallel::par_azip;

src/lib.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,18 @@
8484
//! ## Crate Feature Flags
8585
//!
8686
//! The following crate feature flags are available. They are configured in your
87-
//! `Cargo.toml`. See [`doc::crate_feature_flags`] for more information.
87+
//! `Cargo.toml`. See [`crate::doc::crate_feature_flags`] for more information.
8888
//!
8989
//! - `std`: Rust standard library-using functionality (enabled by default)
9090
//! - `serde`: serialization support for serde 1.x
91-
//! - `rayon`: Parallel iterators, parallelized methods, the [`parallel`] module and [`par_azip!`].
91+
#![cfg_attr(
92+
not(feature = "rayon"),
93+
doc = "//! - `rayon`: Parallel iterators, parallelized methods, and the `par_azip!` macro."
94+
)]
95+
#![cfg_attr(
96+
feature = "rayon",
97+
doc = "//! - `rayon`: Parallel iterators, parallelized methods, the [`parallel`] module and [`par_azip!`]."
98+
)]
9299
//! - `approx` Implementations of traits from the [`approx`] crate.
93100
//! - `blas`: transparent BLAS support for matrix multiplication, needs configuration.
94101
//! - `matrixmultiply-threading`: Use threading from `matrixmultiply`.
@@ -129,7 +136,7 @@ extern crate std;
129136
#[cfg(feature = "blas")]
130137
extern crate cblas_sys;
131138

132-
#[cfg(docsrs)]
139+
#[cfg(any(doc, docsrs))]
133140
pub mod doc;
134141

135142
use alloc::fmt::Debug;

src/linalg/impl_linalg.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,63 @@ where
968968
is_blas_2d(a._dim(), a._strides(), BlasOrder::F)
969969
}
970970

971+
/// Dot product for dynamic-dimensional arrays (`ArrayD`).
972+
///
973+
/// For one-dimensional arrays, computes the vector dot product, which is the sum
974+
/// of the elementwise products (no conjugation of complex operands).
975+
/// Both arrays must have the same length.
976+
///
977+
/// For two-dimensional arrays, performs matrix multiplication. The array shapes
978+
/// must be compatible in the following ways:
979+
/// - If `self` is *M* × *N*, then `rhs` must be *N* × *K* for matrix-matrix multiplication
980+
/// - If `self` is *M* × *N* and `rhs` is *N*, returns a vector of length *M*
981+
/// - If `self` is *M* and `rhs` is *M* × *N*, returns a vector of length *N*
982+
/// - If both arrays are one-dimensional of length *N*, returns a scalar
983+
///
984+
/// **Panics** if:
985+
/// - The arrays have dimensions other than 1 or 2
986+
/// - The array shapes are incompatible for the operation
987+
/// - For vector dot product: the vectors have different lengths
988+
impl<A> Dot<ArrayRef<A, IxDyn>> for ArrayRef<A, IxDyn>
989+
where A: LinalgScalar
990+
{
991+
type Output = Array<A, IxDyn>;
992+
993+
fn dot(&self, rhs: &ArrayRef<A, IxDyn>) -> Self::Output
994+
{
995+
match (self.ndim(), rhs.ndim()) {
996+
(1, 1) => {
997+
let a = self.view().into_dimensionality::<Ix1>().unwrap();
998+
let b = rhs.view().into_dimensionality::<Ix1>().unwrap();
999+
let result = a.dot(&b);
1000+
ArrayD::from_elem(vec![], result)
1001+
}
1002+
(2, 2) => {
1003+
// Matrix-matrix multiplication
1004+
let a = self.view().into_dimensionality::<Ix2>().unwrap();
1005+
let b = rhs.view().into_dimensionality::<Ix2>().unwrap();
1006+
let result = a.dot(&b);
1007+
result.into_dimensionality::<IxDyn>().unwrap()
1008+
}
1009+
(2, 1) => {
1010+
// Matrix-vector multiplication
1011+
let a = self.view().into_dimensionality::<Ix2>().unwrap();
1012+
let b = rhs.view().into_dimensionality::<Ix1>().unwrap();
1013+
let result = a.dot(&b);
1014+
result.into_dimensionality::<IxDyn>().unwrap()
1015+
}
1016+
(1, 2) => {
1017+
// Vector-matrix multiplication
1018+
let a = self.view().into_dimensionality::<Ix1>().unwrap();
1019+
let b = rhs.view().into_dimensionality::<Ix2>().unwrap();
1020+
let result = a.dot(&b);
1021+
result.into_dimensionality::<IxDyn>().unwrap()
1022+
}
1023+
_ => panic!("Dot product for ArrayD is only supported for 1D and 2D arrays"),
1024+
}
1025+
}
1026+
}
1027+
9711028
#[cfg(test)]
9721029
#[cfg(feature = "blas")]
9731030
mod blas_tests
@@ -1083,60 +1140,3 @@ mod blas_tests
10831140
}
10841141
}
10851142
}
1086-
1087-
/// Dot product for dynamic-dimensional arrays (`ArrayD`).
1088-
///
1089-
/// For one-dimensional arrays, computes the vector dot product, which is the sum
1090-
/// of the elementwise products (no conjugation of complex operands).
1091-
/// Both arrays must have the same length.
1092-
///
1093-
/// For two-dimensional arrays, performs matrix multiplication. The array shapes
1094-
/// must be compatible in the following ways:
1095-
/// - If `self` is *M* × *N*, then `rhs` must be *N* × *K* for matrix-matrix multiplication
1096-
/// - If `self` is *M* × *N* and `rhs` is *N*, returns a vector of length *M*
1097-
/// - If `self` is *M* and `rhs` is *M* × *N*, returns a vector of length *N*
1098-
/// - If both arrays are one-dimensional of length *N*, returns a scalar
1099-
///
1100-
/// **Panics** if:
1101-
/// - The arrays have dimensions other than 1 or 2
1102-
/// - The array shapes are incompatible for the operation
1103-
/// - For vector dot product: the vectors have different lengths
1104-
impl<A> Dot<ArrayRef<A, IxDyn>> for ArrayRef<A, IxDyn>
1105-
where A: LinalgScalar
1106-
{
1107-
type Output = Array<A, IxDyn>;
1108-
1109-
fn dot(&self, rhs: &ArrayRef<A, IxDyn>) -> Self::Output
1110-
{
1111-
match (self.ndim(), rhs.ndim()) {
1112-
(1, 1) => {
1113-
let a = self.view().into_dimensionality::<Ix1>().unwrap();
1114-
let b = rhs.view().into_dimensionality::<Ix1>().unwrap();
1115-
let result = a.dot(&b);
1116-
ArrayD::from_elem(vec![], result)
1117-
}
1118-
(2, 2) => {
1119-
// Matrix-matrix multiplication
1120-
let a = self.view().into_dimensionality::<Ix2>().unwrap();
1121-
let b = rhs.view().into_dimensionality::<Ix2>().unwrap();
1122-
let result = a.dot(&b);
1123-
result.into_dimensionality::<IxDyn>().unwrap()
1124-
}
1125-
(2, 1) => {
1126-
// Matrix-vector multiplication
1127-
let a = self.view().into_dimensionality::<Ix2>().unwrap();
1128-
let b = rhs.view().into_dimensionality::<Ix1>().unwrap();
1129-
let result = a.dot(&b);
1130-
result.into_dimensionality::<IxDyn>().unwrap()
1131-
}
1132-
(1, 2) => {
1133-
// Vector-matrix multiplication
1134-
let a = self.view().into_dimensionality::<Ix1>().unwrap();
1135-
let b = rhs.view().into_dimensionality::<Ix2>().unwrap();
1136-
let result = a.dot(&b);
1137-
result.into_dimensionality::<IxDyn>().unwrap()
1138-
}
1139-
_ => panic!("Dot product for ArrayD is only supported for 1D and 2D arrays"),
1140-
}
1141-
}
1142-
}

src/zip/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ where D: Dimension
424424
}
425425

426426
#[cfg(feature = "rayon")]
427+
#[allow(dead_code)]
427428
pub(crate) fn uninitialized_for_current_layout<T>(&self) -> Array<MaybeUninit<T>, D>
428429
{
429430
let is_f = self.prefer_f();

tests/array.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
)]
55

66
use approx::assert_relative_eq;
7+
use core::panic;
78
use defmac::defmac;
89
#[allow(deprecated)]
910
use itertools::{zip, Itertools};
@@ -1005,7 +1006,7 @@ fn iter_size_hint()
10051006
fn zero_axes()
10061007
{
10071008
let mut a = arr1::<f32>(&[]);
1008-
if let Some(_) = a.iter().next() {
1009+
if a.iter().next().is_some() {
10091010
panic!();
10101011
}
10111012
a.map(|_| panic!());
@@ -2080,7 +2081,7 @@ fn test_contiguous()
20802081
assert!(c.as_slice_memory_order().is_some());
20812082
let v = c.slice(s![.., 0..1, ..]);
20822083
assert!(!v.is_standard_layout());
2083-
assert!(!v.as_slice_memory_order().is_some());
2084+
assert!(v.as_slice_memory_order().is_none());
20842085

20852086
let v = c.slice(s![1..2, .., ..]);
20862087
assert!(v.is_standard_layout());

tests/iterators.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn inner_iter_corner_cases()
195195
assert_equal(a0.rows(), vec![aview1(&[0])]);
196196

197197
let a2 = ArcArray::<i32, _>::zeros((0, 3));
198-
assert_equal(a2.rows(), vec![aview1(&[]); 0]);
198+
assert_equal(a2.rows(), Vec::<ArrayView1<'_, i32>>::new());
199199

200200
let a2 = ArcArray::<i32, _>::zeros((3, 0));
201201
assert_equal(a2.rows(), vec![aview1(&[]); 3]);
@@ -359,11 +359,13 @@ fn axis_iter_zip_partially_consumed_discontiguous()
359359
}
360360
}
361361

362+
use ndarray::ArrayView1;
363+
362364
#[test]
363365
fn outer_iter_corner_cases()
364366
{
365367
let a2 = ArcArray::<i32, _>::zeros((0, 3));
366-
assert_equal(a2.outer_iter(), vec![aview1(&[]); 0]);
368+
assert_equal(a2.outer_iter(), Vec::<ArrayView1<'_, i32>>::new());
367369

368370
let a2 = ArcArray::<i32, _>::zeros((3, 0));
369371
assert_equal(a2.outer_iter(), vec![aview1(&[]); 3]);

tests/numeric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn var_too_large_ddof()
175175
fn var_nan_ddof()
176176
{
177177
let a = Array2::<f64>::zeros((2, 3));
178-
let v = a.var(std::f64::NAN);
178+
let v = a.var(f64::NAN);
179179
assert!(v.is_nan());
180180
}
181181

tests/oper.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ fn test_oper(op: &str, a: &[f32], b: &[f32], c: &[f32])
1919
let aa = CowArray::from(arr1(a));
2020
let bb = CowArray::from(arr1(b));
2121
let cc = CowArray::from(arr1(c));
22-
test_oper_arr::<f32, _>(op, aa.clone(), bb.clone(), cc.clone());
22+
test_oper_arr(op, aa.clone(), bb.clone(), cc.clone());
2323
let dim = (2, 2);
2424
let aa = aa.to_shape(dim).unwrap();
2525
let bb = bb.to_shape(dim).unwrap();
2626
let cc = cc.to_shape(dim).unwrap();
27-
test_oper_arr::<f32, _>(op, aa.clone(), bb.clone(), cc.clone());
27+
test_oper_arr(op, aa.clone(), bb.clone(), cc.clone());
2828
let dim = (1, 2, 1, 2);
2929
let aa = aa.to_shape(dim).unwrap();
3030
let bb = bb.to_shape(dim).unwrap();
3131
let cc = cc.to_shape(dim).unwrap();
32-
test_oper_arr::<f32, _>(op, aa.clone(), bb.clone(), cc.clone());
32+
test_oper_arr(op, aa.clone(), bb.clone(), cc.clone());
3333
}
3434

35-
fn test_oper_arr<A, D>(op: &str, mut aa: CowArray<f32, D>, bb: CowArray<f32, D>, cc: CowArray<f32, D>)
35+
fn test_oper_arr<D>(op: &str, mut aa: CowArray<f32, D>, bb: CowArray<f32, D>, cc: CowArray<f32, D>)
3636
where D: Dimension
3737
{
3838
match op {

0 commit comments

Comments
 (0)