Improved style [skip ci]
This commit is contained in:
@@ -6,7 +6,7 @@ use std::os::raw::{c_char, c_double, c_float, c_int, c_longlong};
|
||||
pub struct MfNode {
|
||||
pub u: c_int,
|
||||
pub v: c_int,
|
||||
pub r: c_float
|
||||
pub r: c_float,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -14,7 +14,7 @@ pub struct MfProblem {
|
||||
pub m: c_int,
|
||||
pub n: c_int,
|
||||
pub nnz: c_longlong,
|
||||
pub r: *const MfNode
|
||||
pub r: *const MfNode,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -34,7 +34,7 @@ pub struct MfParameter {
|
||||
pub c: c_float,
|
||||
pub do_nmf: bool,
|
||||
pub quiet: bool,
|
||||
pub copy_data: bool
|
||||
pub copy_data: bool,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -45,7 +45,7 @@ pub struct MfModel {
|
||||
pub k: c_int,
|
||||
pub b: c_float,
|
||||
pub p: *const c_float,
|
||||
pub q: *const c_float
|
||||
pub q: *const c_float,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
@@ -59,7 +59,7 @@ pub enum Loss {
|
||||
BinaryL1 = 7,
|
||||
OneClassRow = 10,
|
||||
OneClassCol = 11,
|
||||
OneClassL2 = 12
|
||||
OneClassL2 = 12,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
|
||||
@@ -6,7 +6,7 @@ use std::fmt;
|
||||
pub enum Error {
|
||||
Io,
|
||||
Parameter(String),
|
||||
Unknown
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl error::Error for Error {}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
use crate::bindings::{MfNode, MfProblem};
|
||||
|
||||
pub struct Matrix {
|
||||
data: Vec<MfNode>
|
||||
data: Vec<MfNode>,
|
||||
}
|
||||
|
||||
impl Matrix {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
data: Vec::new()
|
||||
}
|
||||
Self { data: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
Self {
|
||||
data: Vec::with_capacity(capacity)
|
||||
data: Vec::with_capacity(capacity),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn push(&mut self, row_index: i32, column_index: i32, value: f32) {
|
||||
assert!(row_index >= 0);
|
||||
assert!(column_index >= 0);
|
||||
self.data.push(MfNode { u: row_index, v: column_index, r: value });
|
||||
self.data.push(MfNode {
|
||||
u: row_index,
|
||||
v: column_index,
|
||||
r: value,
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn to_problem(&self) -> MfProblem {
|
||||
@@ -32,7 +34,7 @@ impl Matrix {
|
||||
m,
|
||||
n,
|
||||
nnz: data.len() as i64,
|
||||
r: data.as_ptr()
|
||||
r: data.as_ptr(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,16 +2,14 @@ use crate::bindings::*;
|
||||
use crate::{Error, Loss, Matrix, Model};
|
||||
|
||||
pub struct Params {
|
||||
param: MfParameter
|
||||
param: MfParameter,
|
||||
}
|
||||
|
||||
impl Params {
|
||||
pub(crate) fn new() -> Self {
|
||||
let mut param = unsafe { mf_get_default_param() };
|
||||
param.nr_bins = 25;
|
||||
Self {
|
||||
param
|
||||
}
|
||||
Self { param }
|
||||
}
|
||||
|
||||
pub fn loss(&mut self, value: Loss) -> &mut Self {
|
||||
|
||||
Reference in New Issue
Block a user