Renamed methods to p and q

This commit is contained in:
Andrew Kane
2022-09-23 12:51:10 -07:00
parent fc1366cb9e
commit 4c92b71187
3 changed files with 11 additions and 11 deletions

View File

@@ -1,7 +1,7 @@
## 0.2.2 (unreleased)
- Added `p_iter` and `q_iter`
- Added `p_row` and `q_col`
- Added `p` and `q`
## 0.2.1 (2021-11-15)

View File

@@ -47,8 +47,8 @@ model.q_factors();
Get the latent factors of a specific row or column [unreleased]
```rust
model.p_row(row_index);
model.q_col(column_index);
model.p(index);
model.q(index);
```
Get the bias (average of all elements in the training matrix)

View File

@@ -70,7 +70,7 @@ impl Model {
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() {
let factors = self.factors();
let start_index = factors as usize * row_index as usize;
@@ -80,7 +80,7 @@ impl Model {
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() {
let factors = self.factors();
let start_index = factors as usize * column_index as usize;
@@ -178,13 +178,13 @@ mod tests {
assert_eq!(factors, q_vec[i]);
}
assert_eq!(model.p_row(0), Some(p_vec[0]));
assert_eq!(model.p_row(1), Some(p_vec[1]));
assert_eq!(model.p_row(2), None);
assert_eq!(model.p(0), Some(p_vec[0]));
assert_eq!(model.p(1), Some(p_vec[1]));
assert_eq!(model.p(2), None);
assert_eq!(model.q_col(0), Some(q_vec[0]));
assert_eq!(model.q_col(1), Some(q_vec[1]));
assert_eq!(model.q_col(2), None);
assert_eq!(model.q(0), Some(q_vec[0]));
assert_eq!(model.q(1), Some(q_vec[1]));
assert_eq!(model.q(2), None);
}
#[test]