Renamed methods to p and q
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
## 0.2.2 (unreleased)
|
## 0.2.2 (unreleased)
|
||||||
|
|
||||||
- Added `p_iter` and `q_iter`
|
- Added `p_iter` and `q_iter`
|
||||||
- Added `p_row` and `q_col`
|
- Added `p` and `q`
|
||||||
|
|
||||||
## 0.2.1 (2021-11-15)
|
## 0.2.1 (2021-11-15)
|
||||||
|
|
||||||
|
|||||||
@@ -47,8 +47,8 @@ model.q_factors();
|
|||||||
Get the latent factors of a specific row or column [unreleased]
|
Get the latent factors of a specific row or column [unreleased]
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
model.p_row(row_index);
|
model.p(index);
|
||||||
model.q_col(column_index);
|
model.q(index);
|
||||||
```
|
```
|
||||||
|
|
||||||
Get the bias (average of all elements in the training matrix)
|
Get the bias (average of all elements in the training matrix)
|
||||||
|
|||||||
16
src/model.rs
16
src/model.rs
@@ -70,7 +70,7 @@ impl Model {
|
|||||||
unsafe { std::slice::from_raw_parts((*self.model).q, (self.columns() * self.factors()) as usize) }
|
unsafe { std::slice::from_raw_parts((*self.model).q, (self.columns() * self.factors()) as usize) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn p_row(&self, row_index: i32) -> Option<&[f32]>{
|
pub fn p(&self, row_index: i32) -> Option<&[f32]>{
|
||||||
if row_index >= 0 && row_index < self.rows() {
|
if row_index >= 0 && row_index < self.rows() {
|
||||||
let factors = self.factors();
|
let factors = self.factors();
|
||||||
let start_index = factors as usize * row_index as usize;
|
let start_index = factors as usize * row_index as usize;
|
||||||
@@ -80,7 +80,7 @@ impl Model {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn q_col(&self, column_index: i32) -> Option<&[f32]>{
|
pub fn q(&self, column_index: i32) -> Option<&[f32]>{
|
||||||
if column_index >= 0 && column_index < self.columns() {
|
if column_index >= 0 && column_index < self.columns() {
|
||||||
let factors = self.factors();
|
let factors = self.factors();
|
||||||
let start_index = factors as usize * column_index as usize;
|
let start_index = factors as usize * column_index as usize;
|
||||||
@@ -178,13 +178,13 @@ mod tests {
|
|||||||
assert_eq!(factors, q_vec[i]);
|
assert_eq!(factors, q_vec[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(model.p_row(0), Some(p_vec[0]));
|
assert_eq!(model.p(0), Some(p_vec[0]));
|
||||||
assert_eq!(model.p_row(1), Some(p_vec[1]));
|
assert_eq!(model.p(1), Some(p_vec[1]));
|
||||||
assert_eq!(model.p_row(2), None);
|
assert_eq!(model.p(2), None);
|
||||||
|
|
||||||
assert_eq!(model.q_col(0), Some(q_vec[0]));
|
assert_eq!(model.q(0), Some(q_vec[0]));
|
||||||
assert_eq!(model.q_col(1), Some(q_vec[1]));
|
assert_eq!(model.q(1), Some(q_vec[1]));
|
||||||
assert_eq!(model.q_col(2), None);
|
assert_eq!(model.q(2), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user