Improved style [skip ci]

This commit is contained in:
Andrew Kane
2023-05-07 07:32:29 -07:00
parent acdedb7048
commit e323256949
5 changed files with 18 additions and 18 deletions

View File

@@ -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" {

View File

@@ -6,7 +6,7 @@ use std::fmt;
pub enum Error {
Io,
Parameter(String),
Unknown
Unknown,
}
impl error::Error for Error {}

View File

@@ -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(),
}
}
}

View File

@@ -17,7 +17,7 @@ impl Model {
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
// TODO better conversion
let cpath = CString::new(path.as_ref().to_str().unwrap())?;
let model = unsafe { mf_load_model(cpath.as_ptr()) };
let model = unsafe { mf_load_model(cpath.as_ptr()) };
if model.is_null() {
return Err(Error::Io);
}

View File

@@ -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 {