Skip to content

Commit

Permalink
renamed Vector::mut_at -> at_mut
Browse files Browse the repository at this point in the history
  • Loading branch information
Klein, Markus authored and Klein, Markus committed Nov 15, 2016
1 parent 1e8a8a7 commit bea880f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
8 changes: 2 additions & 6 deletions src/cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ pub struct LeastAbsoluteDeviation;
impl Cost<f64> for LeastAbsoluteDeviation {
fn outer_derivative(&self, prediction: &f64, truth: f64) -> f64 {
let error = prediction - truth;
if error == 0.0 {
0.0
} else {
error.signum()
}
if error == 0.0 { 0.0 } else { error.signum() }
}
fn cost(&self, prediction: f64, truth: f64) -> f64 {
(prediction - truth).abs()
Expand Down Expand Up @@ -98,7 +94,7 @@ impl<V> Cost<usize, V> for MaxLikelihood
fn outer_derivative(&self, prediction: &V, truth: usize) -> V {
let mut derivation = prediction.clone();
for i in 0..prediction.dimension() {
*derivation.mut_at(i) = self.outer_derivative(&prediction.at(i), truth == i);
*derivation.at_mut(i) = self.outer_derivative(&prediction.at(i), truth == i);
}
derivation
}
Expand Down
8 changes: 4 additions & 4 deletions src/linear_algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ pub trait Vector: Clone {
/// Not every possible implementation knows its dimension at compiletime, therefore a size hint
/// is necessary to allocate the correct number of elements
fn zero(dimension: usize) -> Self;
/// Maximum allowed index for `at` and `mut_at`
/// Maximum allowed index for `at` and `at_mut`
fn dimension(&self) -> usize;
/// Length of projection along `i`-th base
fn at(&self, i: usize) -> f64;
/// Mutable access to length of projection along `i`-th base
fn mut_at(&mut self, i: usize) -> &mut f64;
fn at_mut(&mut self, i: usize) -> &mut f64;
/// Scalar product
///
/// Default implementation using `at` and `dimension` is provided
Expand All @@ -40,7 +40,7 @@ impl Vector for f64 {
assert!(i == 0);
*self
}
fn mut_at(&mut self, i: usize) -> &mut f64 {
fn at_mut(&mut self, i: usize) -> &mut f64 {
assert!(i == 0);
self
}
Expand All @@ -63,7 +63,7 @@ macro_rules! vec_impl_for_array {
self[index]
}

fn mut_at(&mut self, index: usize) -> &mut f64 {
fn at_mut(&mut self, index: usize) -> &mut f64 {
&mut self[index]
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<V> Model for Linear<V>
if coefficient == self.m.dimension() {
&mut self.c
} else {
self.m.mut_at(coefficient)
self.m.at_mut(coefficient)
}
}

Expand Down Expand Up @@ -203,7 +203,7 @@ impl<T> Model for OneVsRest<T>
let models = &self.0;
let mut result = Self::Target::zero(models.length());
for i in 0..models.length() {
*result.mut_at(i) = models.at_ref(i).predict(input);
*result.at_mut(i) = models.at_ref(i).predict(input);
}
result
}
Expand All @@ -212,7 +212,7 @@ impl<T> Model for OneVsRest<T>
let models = &self.0;
let class = coefficient % models.length();
let mut result = Self::Target::zero(models.length());
*result.mut_at(class) = models.at_ref(class).gradient(coefficient / models.length(), input);
*result.at_mut(class) = models.at_ref(class).gradient(coefficient / models.length(), input);
result
}
}

0 comments on commit bea880f

Please sign in to comment.