Skip to content

Commit

Permalink
add Result to csolve output
Browse files Browse the repository at this point in the history
  • Loading branch information
attack68 committed Mar 28, 2024
1 parent 2a07955 commit 74bb0d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/splines/spline_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use ndarray::{Array1, Array2};
use num_traits::{Signed, Zero};
use std::iter::Sum;
use std::ops::{Mul, Sub};
use pyo3::PyErr;
use pyo3::exceptions::PyValueError;

pub fn bsplev_single_f64(x: &f64, i: usize, k: &usize, t: &Vec<f64>, org_k: Option<usize>) -> f64 {
let org_k: usize = org_k.unwrap_or(*k);
Expand Down Expand Up @@ -164,18 +166,23 @@ where
left_n: usize,
right_n: usize,
allow_lsq: bool,
)
) -> Result<(), PyErr>
{
if tau.len() != self.n && !(allow_lsq && tau.len() > self.n) {
panic!("`csolve` cannot complete if length of `tau` < n or `allow_lsq` is false.")
return Err(PyValueError::new_err(
"`csolve` cannot complete if length of `tau` < n or `allow_lsq` is false."
))
}
if tau.len() != y.len() {
panic!("`tau` and `y` must have the same length.")
return Err(PyValueError::new_err(
"`tau` and `y` must have the same length."
))
}
let b: Array2<f64> = self.bsplmatrix(tau, left_n, right_n);
let ya: Array1<T> = Array1::from_vec(y.clone());
let c: Array1<T> = fdsolve(&b.view(), &ya.view(), allow_lsq);
self.c = Some(c);
Ok(())
}

pub fn bsplev(&self, x: &Vec<f64>, i: &usize) -> Vec<f64> {
Expand Down
2 changes: 1 addition & 1 deletion src/splines/spline_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ macro_rules! create_interface {
left_n: usize,
right_n: usize,
allow_lsq: bool
) {
) -> PyResult<()> {
self.inner.csolve(&tau, &y, left_n, right_n, allow_lsq)
}

Expand Down

0 comments on commit 74bb0d5

Please sign in to comment.