Skip to content

Commit d905ebe

Browse files
authored
Added additional doctest and fixed indices (#141)
1 parent b482acd commit d905ebe

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

src/algorithm/neighbour/bbd_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<T: RealNumber> BBDTree<T> {
5959
tree
6060
}
6161

62-
pub(in crate) fn clustering(
62+
pub(crate) fn clustering(
6363
&self,
6464
centroids: &[Vec<T>],
6565
sums: &mut Vec<Vec<T>>,

src/linalg/evd.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@
2525
//! let eigenvectors: DenseMatrix<f64> = evd.V;
2626
//! let eigenvalues: Vec<f64> = evd.d;
2727
//! ```
28+
//! ```
29+
//! use smartcore::linalg::naive::dense_matrix::*;
30+
//! use smartcore::linalg::evd::*;
31+
//!
32+
//! let A = DenseMatrix::from_2d_array(&[
33+
//! &[-5.0, 2.0],
34+
//! &[-7.0, 4.0],
35+
//! ]);
36+
//!
37+
//! let evd = A.evd(false).unwrap();
38+
//! let eigenvectors: DenseMatrix<f64> = evd.V;
39+
//! let eigenvalues: Vec<f64> = evd.d;
40+
//! ```
2841
//!
2942
//! ## References:
3043
//! * ["Numerical Recipes: The Art of Scientific Computing", Press W.H., Teukolsky S.A., Vetterling W.T, Flannery B.P, 3rd ed., Section 11 Eigensystems](http://numerical.recipes/)
@@ -799,10 +812,10 @@ fn sort<T: RealNumber, M: BaseMatrix<T>>(d: &mut [T], e: &mut [T], V: &mut M) {
799812
}
800813
i -= 1;
801814
}
802-
d[i as usize + 1] = real;
803-
e[i as usize + 1] = img;
815+
d[(i + 1) as usize] = real;
816+
e[(i + 1) as usize] = img;
804817
for (k, temp_k) in temp.iter().enumerate().take(n) {
805-
V.set(k, i as usize + 1, *temp_k);
818+
V.set(k, (i + 1) as usize, *temp_k);
806819
}
807820
}
808821
}

src/optimization/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub type F<'a, T, X> = dyn for<'b> Fn(&'b X) -> T + 'a;
55
pub type DF<'a, X> = dyn for<'b> Fn(&'b mut X, &'b X) + 'a;
66

77
#[allow(clippy::upper_case_acronyms)]
8-
#[derive(Debug, PartialEq)]
8+
#[derive(Debug, PartialEq, Eq)]
99
pub enum FunctionOrder {
1010
SECOND,
1111
THIRD,

src/svm/svr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ impl<T: RealNumber, M: Matrix<T>, K: Kernel<T, M::RowVector>> SVR<T, M, K> {
242242
Ok(y_hat)
243243
}
244244

245-
pub(in crate) fn predict_for_row(&self, x: M::RowVector) -> T {
245+
pub(crate) fn predict_for_row(&self, x: M::RowVector) -> T {
246246
let mut f = self.b;
247247

248248
for i in 0..self.instances.len() {

src/tree/decision_tree_classifier.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'a, T: RealNumber, M: Matrix<T>> NodeVisitor<'a, T, M> {
285285
}
286286
}
287287

288-
pub(in crate) fn which_max(x: &[usize]) -> usize {
288+
pub(crate) fn which_max(x: &[usize]) -> usize {
289289
let mut m = x[0];
290290
let mut which = 0;
291291

@@ -421,7 +421,7 @@ impl<T: RealNumber> DecisionTreeClassifier<T> {
421421
Ok(result.to_row_vector())
422422
}
423423

424-
pub(in crate) fn predict_for_row<M: Matrix<T>>(&self, x: &M, row: usize) -> usize {
424+
pub(crate) fn predict_for_row<M: Matrix<T>>(&self, x: &M, row: usize) -> usize {
425425
let mut result = 0;
426426
let mut queue: LinkedList<usize> = LinkedList::new();
427427

src/tree/decision_tree_regressor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl<T: RealNumber> DecisionTreeRegressor<T> {
321321
Ok(result.to_row_vector())
322322
}
323323

324-
pub(in crate) fn predict_for_row<M: Matrix<T>>(&self, x: &M, row: usize) -> T {
324+
pub(crate) fn predict_for_row<M: Matrix<T>>(&self, x: &M, row: usize) -> T {
325325
let mut result = T::zero();
326326
let mut queue: LinkedList<usize> = LinkedList::new();
327327

0 commit comments

Comments
 (0)