Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Feb 16, 2024
1 parent c51fd66 commit a6a5c89
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 1 addition & 9 deletions src/dual/dual1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Dual {
}

/// Return a Dual with recast vars if required.
pub fn to_new_ordered_vars(&self, new_vars: &Arc<IndexSet<String>>) -> Dual {
fn to_new_ordered_vars(&self, new_vars: &Arc<IndexSet<String>>) -> Dual {
if self.vars.len() == new_vars.len() && self.vars.iter().zip(new_vars.iter()).all(|(a,b)| a==b) {
Dual {vars: Arc::clone(new_vars), real: self.real, dual: self.dual.clone()}
} else {
Expand Down Expand Up @@ -564,26 +564,21 @@ impl_op_ex_commutative!(+ |a: &Dual, b: &f64| -> Dual { Dual {vars: Arc::clone(&
// }
// });



// Subtraction
impl_op_ex!(- |a: &Dual, b: &f64| -> Dual { Dual {vars: Arc::clone(&a.vars), real: a.real - b, dual: a.dual.clone()} });
impl_op_ex!(- |a: &f64, b: &Dual| -> Dual { Dual {vars: Arc::clone(&b.vars), real: a - b.real, dual: -(b.dual.clone())} });


// multiplication
impl_op_ex_commutative!(* |a: &Dual, b: f64| -> Dual { Dual {vars: Arc::clone(&a.vars), real: a.real * b, dual: b * &a.dual} });

// division
impl_op_ex!(/ |a: &Dual, b: f64| -> Dual { Dual {vars: Arc::clone(&a.vars), real: a.real / b, dual: &a.dual / b} });
impl_op_ex!(/ |a: f64, b: &Dual| -> Dual { a * b.clone().pow(-1.0) });


// remainder
impl_op_ex!(% |a: &Dual, b: &f64| -> Dual { Dual {vars: Arc::clone(&a.vars), real: a.real % b, dual: a.dual.clone()} });
impl_op_ex!(% |a: &f64, b: &Dual| -> Dual { Dual::new(*a, Vec::new(), Vec::new()) % b });


impl PartialEq<f64> for Dual {
fn eq(&self, other: &f64) -> bool {
return Dual::new(*other, [].to_vec(), [].to_vec()) == *self;
Expand All @@ -596,8 +591,6 @@ impl PartialEq<Dual> for f64 {
}
}



impl PartialOrd<f64> for Dual {
fn partial_cmp(&self, other: &f64) -> Option<Ordering>{
if self.real == *other {
Expand Down Expand Up @@ -769,7 +762,6 @@ fn abs() {
assert_eq!(result, expected)
}


#[test]
fn div_f64() {
let d1 = Dual::new(1.0, vec!["v0".to_string(), "v1".to_string()], vec![1.0, 2.0]);
Expand Down
10 changes: 5 additions & 5 deletions src/dual/linalg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ use std::cmp::PartialOrd;
// OnUnderlying,
// }
//
// fn argabsmax<i32: Signed + PartialOrd>(a: ArrayView1<i32>) -> usize {
// let a: (usize, i32) = a.iter().enumerate().fold((0, 0), |acc, (i, elem)| {
// if elem.abs() > acc.1 { (i, *elem.clone()) } else { acc }
// });
// a.0
// fn argabsmax<T: Signed + PartialOrd>(a: ArrayView1<T>) -> usize {
// let a: (&T, usize) = a.iter().zip(0..).max_by(
// |x,y| x.0.abs().partial_cmp(&y.0.abs()).unwrap()
// ).unwrap();
// a.1
// }
//
// pub fn pivot_matrix(A: &Array2<i32>) -> (Array2<i32>, Array2<i32>) {
Expand Down

0 comments on commit a6a5c89

Please sign in to comment.