pub fn sparse_problem(y: Vec<f64>, x: Vec<Vec<(i32, f64)>>) -> Result<SvmProb> {
    // Data check: Problem is not empty
    if y.len() == 0 || x.len() == 0 {
        return Err(SvmErr::InvalidDataError(format!("Cannot create problem from empty vector")))
    }

    // Data check: output and input vectors have the same length
    let len = y.len();
    if x.len() != len {
        return Err(SvmErr::InvalidDataError(
            format!("y vector has length {} but x vector has length {}", len, x.len())))
    }

    // Build the problem struct
    let mut x_data = Vec::new();
    for row in x {
        let mut new_row = Vec::new();
        for (i, cell) in row {
            if cell != 0.0 {
                new_row.push(sys::CSVMNode { index: i, value: cell });
            }
        }
        new_row.push(sys::CSVMNode { index: -1, value: 0.0 });
        x_data.push(new_row.as_ptr());
    }

    Ok(SvmProb {
        c_problem: sys::CSVMProb {
            l: len as i32,
            y: y.as_ptr(),
            data: x_data.as_ptr()
        }
    })
}
/// Create an SvmProb from a vector of output variables and a vector of feature vectors represented
/// as (index, value) pairs.
Create an SvmProb from a vector of output variables and a vector of feature vectors represented
as (index, value) pairs.
Create an SvmProb from a vector of output variables and a vector of feature vectors represented as ( index value ) pairs .
pub fn sparse_problem(y: Vec<f64>, x: Vec<Vec<(i32, f64)>>) -> Result<SvmProb> {
    // Data check: Problem is not empty
    if y.len() == 0 || x.len() == 0 {
        return Err(SvmErr::InvalidDataError(format!("Cannot create problem from empty vector")))
    }
    // Data check: output and input vectors have the same length
    let len = y.len();
    if x.len() != len {
        return Err(SvmErr::InvalidDataError(
            format!("y vector has length {} but x vector has length {}", len, x.len())))
    }
    // Build the problem struct
    let mut x_data = Vec::new();
    for row in x {
        let mut new_row = Vec::new();
        for (i, cell) in row {
            if cell != 0.0 {
                new_row.push(sys::CSVMNode { index: i, value: cell });
            }
        }
        new_row.push(sys::CSVMNode { index: -1, value: 0.0 });
        x_data.push(new_row.as_ptr());
    }
    Ok(SvmProb {
        c_problem: sys::CSVMProb {
            l: len as i32,
            y: y.as_ptr(),
            data: x_data.as_ptr()
        }
    })
}
pub fn sparse_problem ( y : Vec < f64 > , x : Vec < Vec < ( i32 , f64 ) > > ) -> Result < SvmProb > { // Data check: Problem is not empty if y . len ( ) == 0 || x . len ( ) == 0 { return Err ( SvmErr :: InvalidDataError ( format ! ( " " ) ) ) } // Data check: output and input vectors have the same length let len = y . len ( ) ; if x . len ( ) != len { return Err ( SvmErr :: InvalidDataError ( format ! ( " " len x len ( ) ) ) ) } // Build the problem struct let mut x_data = Vec :: new ( ) ; for row in x { let mut new_row = Vec :: new ( ) ; for ( i , cell ) in row { if cell != 0.0 { new_row . push ( sys :: CSVMNode { index : i , value : cell } ) ; } } new_row . push ( sys :: CSVMNode { index : - 1 , value : 0.0 } ) ; x_data . push ( new_row . as_ptr ( ) ) ; } Ok ( SvmProb { c_problem : sys :: CSVMProb { l : len as i32 , y : y . as_ptr ( ) , data : x_data . as_ptr ( ) } } ) }
Create an SvmProb from a vector of output variables and a vector of feature vectors represented
as (index, value) pairs.
Create an SvmProb from a vector of output variables and a vector of feature vectors represented as ( index value ) pairs .
y
Vec<f64>
x
Vec<Vec<(i32, f64)>>
y
Vec<f64>
x
Vec<Vec<(i32, f64)>>