Browse Source

Make function that never fails non-fallible

contact-taker-before-changing-cfd-state
Thomas Eizinger 3 years ago
parent
commit
578de0edf8
No known key found for this signature in database GPG Key ID: 651AC83A6C6C8B96
  1. 4
      daemon/src/payout_curve.rs
  2. 8
      daemon/src/payout_curve/curve.rs
  3. 2
      daemon/src/payout_curve/curve_factory.rs
  4. 8
      daemon/src/payout_curve/splineobject.rs

4
daemon/src/payout_curve.rs

@ -270,7 +270,7 @@ impl PayoutCurve {
} }
fn build_sampling_vector_upper_bounded(&self, n_segs: usize) -> Array1<f64> { fn build_sampling_vector_upper_bounded(&self, n_segs: usize) -> Array1<f64> {
let knots = &self.curve.spline.knots(0, None).unwrap()[0]; let knots = &self.curve.spline.knots(0, None)[0];
let klen = knots.len(); let klen = knots.len();
let n_64 = (n_segs + 1) as f64; let n_64 = (n_segs + 1) as f64;
let d = knots[klen - 2] - knots[1]; let d = knots[klen - 2] - knots[1];
@ -300,7 +300,7 @@ impl PayoutCurve {
} }
fn build_sampling_vector_upper_unbounded(&self, n_segs: usize) -> Array1<f64> { fn build_sampling_vector_upper_unbounded(&self, n_segs: usize) -> Array1<f64> {
let knots = &self.curve.spline.knots(0, None).unwrap()[0]; let knots = &self.curve.spline.knots(0, None)[0];
let klen = knots.len(); let klen = knots.len();
let n_64 = (n_segs + 1) as f64; let n_64 = (n_segs + 1) as f64;
let d = knots[klen - 1] - knots[1]; let d = knots[klen - 1] - knots[1];

8
daemon/src/payout_curve/curve.rs

@ -126,8 +126,8 @@ impl Curve {
let p = max(p1, p2); let p = max(p1, p2);
let old_knot = self.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(); let mut add_knot = extending_curve.spline.knots(0, Some(true))[0].clone();
add_knot -= add_knot[0]; add_knot -= add_knot[0];
add_knot += old_knot[old_knot.len() - 1]; add_knot += old_knot[old_knot.len() - 1];
@ -212,7 +212,7 @@ impl Curve {
/// * t0: lower integration limit /// * t0: lower integration limit
/// * t1: upper integration limit /// * t1: upper integration limit
pub fn length(&self, t0: Option<f64>, t1: Option<f64>) -> Result<f64, Error> { pub fn length(&self, t0: Option<f64>, t1: Option<f64>) -> Result<f64, Error> {
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 // keep only integration boundaries within given start (t0) and stop (t1) interval
let new_knots_0 = t0 let new_knots_0 = t0
@ -419,7 +419,7 @@ impl Curve {
&self, &self,
target: impl Fn(&Array1<f64>) -> Array2<f64>, target: impl Fn(&Array1<f64>) -> Array2<f64>,
) -> Result<(Array1<f64>, f64), Error> { ) -> Result<(Array1<f64>, 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 n = self.spline.order(0)?[0];
let gleg = GaussLegendreQuadrature::new(n + 1)?; let gleg = GaussLegendreQuadrature::new(n + 1)?;

2
daemon/src/payout_curve/curve_factory.rs

@ -105,7 +105,7 @@ pub fn fit(
let scale_64 = 12_f64; let scale_64 = 12_f64;
while target > rtol && err_max > atol { 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; let target_error = (rtol * length).powi(2) / err_l2.len() as f64;
for i in 0..err_l2.len() { for i in 0..err_l2.len() {
// figure out how many new knots we require in this knot interval: // figure out how many new knots we require in this knot interval:

8
daemon/src/payout_curve/splineobject.rs

@ -267,11 +267,7 @@ impl SplineObject {
/// * direction: Direction number (axis) in which to get the knots. /// * direction: Direction number (axis) in which to get the knots.
/// * with_multiplicities: If true, return knots with multiplicities \ /// * with_multiplicities: If true, return knots with multiplicities \
/// (i.e. repeated). /// (i.e. repeated).
pub fn knots( pub fn knots(&self, direction: isize, with_multiplicities: Option<bool>) -> Vec<Array1<f64>> {
&self,
direction: isize,
with_multiplicities: Option<bool>,
) -> Result<Vec<Array1<f64>>, Error> {
let with_multiplicities = with_multiplicities.unwrap_or(false); let with_multiplicities = with_multiplicities.unwrap_or(false);
let out; let out;
@ -298,7 +294,7 @@ impl SplineObject {
} }
} }
Ok(out) out
} }
/// This will manipulate one or both to ensure that they are both rational /// This will manipulate one or both to ensure that they are both rational

Loading…
Cancel
Save