1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

use crate::{MatrixF64, Value, VectorF64};
use ffi::FFI;

#[doc(alias = "gsl_multifit_linear_applyW")]
pub fn applyW(
    x: &MatrixF64,
    w: &VectorF64,
    y: &VectorF64,
    wx: &mut MatrixF64,
    wy: &mut VectorF64,
) -> Value {
    unsafe {
        Value::from(sys::gsl_multifit_linear_applyW(
            x.unwrap_shared(),
            w.unwrap_shared(),
            y.unwrap_shared(),
            wx.unwrap_unique(),
            wy.unwrap_unique(),
        ))
    }
}

#[doc(alias = "gsl_multifit_linear_L_decomp")]
pub fn L_decomp(l: &mut MatrixF64, tau: &mut VectorF64) -> Value {
    unsafe {
        Value::from(sys::gsl_multifit_linear_L_decomp(
            l.unwrap_unique(),
            tau.unwrap_unique(),
        ))
    }
}

#[doc(alias = "gsl_multifit_linear_lreg")]
pub fn lreg(smin: f64, smax: f64, reg_param: &mut VectorF64) -> Value {
    unsafe {
        Value::from(sys::gsl_multifit_linear_lreg(
            smin,
            smax,
            reg_param.unwrap_unique(),
        ))
    }
}

/// Returns `(Value, idx)`.
#[doc(alias = "gsl_multifit_linear_lcorner")]
pub fn lcorner(rho: &VectorF64, eta: &VectorF64) -> (Value, usize) {
    let mut idx = 0;
    let ret = unsafe {
        sys::gsl_multifit_linear_lcorner(rho.unwrap_shared(), eta.unwrap_shared(), &mut idx)
    };
    (Value::from(ret), idx)
}

/// Returns `(Value, idx)`.
#[doc(alias = "gsl_multifit_linear_lcorner2")]
pub fn lcorner2(reg_param: &VectorF64, eta: &VectorF64) -> (Value, usize) {
    let mut idx = 0;
    let ret = unsafe {
        sys::gsl_multifit_linear_lcorner2(reg_param.unwrap_shared(), eta.unwrap_shared(), &mut idx)
    };
    (Value::from(ret), idx)
}

#[doc(alias = "gsl_multifit_linear_Lk")]
pub fn Lk(p: usize, k: usize, l: &mut MatrixF64) -> Value {
    unsafe { Value::from(sys::gsl_multifit_linear_Lk(p, k, l.unwrap_unique())) }
}

/// Returns `(Value, y, y_err)`.
#[doc(alias = "gsl_multifit_linear_est")]
pub fn linear_est(x: &VectorF64, c: &VectorF64, cov: &MatrixF64) -> (Value, f64, f64) {
    let mut y = 0.;
    let mut y_err = 0.;
    let ret = unsafe {
        sys::gsl_multifit_linear_est(
            x.unwrap_shared(),
            c.unwrap_shared(),
            cov.unwrap_shared(),
            &mut y,
            &mut y_err,
        )
    };
    (Value::from(ret), y, y_err)
}

#[doc(alias = "gsl_multifit_linear_residuals")]
pub fn linear_residuals(x: &MatrixF64, y: &VectorF64, c: &VectorF64, r: &mut VectorF64) -> Value {
    unsafe {
        Value::from(sys::gsl_multifit_linear_residuals(
            x.unwrap_shared(),
            y.unwrap_shared(),
            c.unwrap_shared(),
            r.unwrap_unique(),
        ))
    }
}