From 578de0edf84d2da5d1a582a0917eb6098330357e Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 20 Oct 2021 17:44:38 +1100 Subject: [PATCH] Make function that never fails non-fallible --- daemon/src/payout_curve.rs | 4 ++-- daemon/src/payout_curve/curve.rs | 8 ++++---- daemon/src/payout_curve/curve_factory.rs | 2 +- daemon/src/payout_curve/splineobject.rs | 8 ++------ 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/daemon/src/payout_curve.rs b/daemon/src/payout_curve.rs index 12c3a48..b4606be 100644 --- a/daemon/src/payout_curve.rs +++ b/daemon/src/payout_curve.rs @@ -270,7 +270,7 @@ impl PayoutCurve { } fn build_sampling_vector_upper_bounded(&self, n_segs: usize) -> Array1 { - let knots = &self.curve.spline.knots(0, None).unwrap()[0]; + let knots = &self.curve.spline.knots(0, None)[0]; let klen = knots.len(); let n_64 = (n_segs + 1) as f64; let d = knots[klen - 2] - knots[1]; @@ -300,7 +300,7 @@ impl PayoutCurve { } fn build_sampling_vector_upper_unbounded(&self, n_segs: usize) -> Array1 { - let knots = &self.curve.spline.knots(0, None).unwrap()[0]; + let knots = &self.curve.spline.knots(0, None)[0]; let klen = knots.len(); let n_64 = (n_segs + 1) as f64; let d = knots[klen - 1] - knots[1]; diff --git a/daemon/src/payout_curve/curve.rs b/daemon/src/payout_curve/curve.rs index c6112eb..41fedb9 100644 --- a/daemon/src/payout_curve/curve.rs +++ b/daemon/src/payout_curve/curve.rs @@ -126,8 +126,8 @@ impl Curve { let p = max(p1, p2); - let old_knot = self.spline.knots(0, Some(true))?[0].clone(); - let mut add_knot = extending_curve.spline.knots(0, Some(true))?[0].clone(); + let old_knot = self.spline.knots(0, Some(true))[0].clone(); + let mut add_knot = extending_curve.spline.knots(0, Some(true))[0].clone(); add_knot -= add_knot[0]; add_knot += old_knot[old_knot.len() - 1]; @@ -212,7 +212,7 @@ impl Curve { /// * t0: lower integration limit /// * t1: upper integration limit pub fn length(&self, t0: Option, t1: Option) -> Result { - let mut knots = &self.spline.knots(0, Some(false))?[0]; + let mut knots = &self.spline.knots(0, Some(false))[0]; // keep only integration boundaries within given start (t0) and stop (t1) interval let new_knots_0 = t0 @@ -419,7 +419,7 @@ impl Curve { &self, target: impl Fn(&Array1) -> Array2, ) -> Result<(Array1, f64), Error> { - let knots = &self.spline.knots(0, Some(false))?[0]; + let knots = &self.spline.knots(0, Some(false))[0]; let n = self.spline.order(0)?[0]; let gleg = GaussLegendreQuadrature::new(n + 1)?; diff --git a/daemon/src/payout_curve/curve_factory.rs b/daemon/src/payout_curve/curve_factory.rs index fa57221..d4e5335 100644 --- a/daemon/src/payout_curve/curve_factory.rs +++ b/daemon/src/payout_curve/curve_factory.rs @@ -105,7 +105,7 @@ pub fn fit( let scale_64 = 12_f64; while target > rtol && err_max > atol { - let knot_span = &crv.spline.knots(0, Some(false))?[0]; + let knot_span = &crv.spline.knots(0, Some(false))[0]; let target_error = (rtol * length).powi(2) / err_l2.len() as f64; for i in 0..err_l2.len() { // figure out how many new knots we require in this knot interval: diff --git a/daemon/src/payout_curve/splineobject.rs b/daemon/src/payout_curve/splineobject.rs index 1b5507a..103ccda 100644 --- a/daemon/src/payout_curve/splineobject.rs +++ b/daemon/src/payout_curve/splineobject.rs @@ -267,11 +267,7 @@ impl SplineObject { /// * direction: Direction number (axis) in which to get the knots. /// * with_multiplicities: If true, return knots with multiplicities \ /// (i.e. repeated). - pub fn knots( - &self, - direction: isize, - with_multiplicities: Option, - ) -> Result>, Error> { + pub fn knots(&self, direction: isize, with_multiplicities: Option) -> Vec> { let with_multiplicities = with_multiplicities.unwrap_or(false); let out; @@ -298,7 +294,7 @@ impl SplineObject { } } - Ok(out) + out } /// This will manipulate one or both to ensure that they are both rational