Skip to content

Commit

Permalink
2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
liborty committed May 2, 2024
1 parent 3e5407f commit 7268df8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ Methods which take an additional generic vector argument, such as a vector of we

## Appendix: Recent Releases

* **Version 2.1.1** - Added function `project` to project a `TriangMat` to a lower dimensional space of selected dimensions. Removed `rows` which was a duplicate of `dim`.

* **Version 2.1.0** - Changed the type of `mid` argument to covariance methods from U -> f64, making the normal expectation for the type of precise geometric medians explicit. Accordingly, moved `covar` and `serial_covar` from trait `VecVecg` to `VecVec`. This might potentially require changing some `use` declarations in your code.

* **Version 2.0.12** - added `depth_ratio`
Expand Down
23 changes: 16 additions & 7 deletions src/triangmat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ impl TriangMat {
pub fn is_empty(&self) -> bool {
self.data.is_empty()
}
/// Square matrix dimension (rows)
pub fn rows(&self) -> usize {
Self::rowcol(self.len()).0
}
/// Squared euclidian vector magnitude (norm) of the data vector
pub fn magsq(&self) -> f64 {
self.data.vmagsq()
Expand Down Expand Up @@ -99,8 +95,7 @@ impl TriangMat {
let mut fullcov = self.to_full();
fullcov.iter_mut().for_each(|eigenvector| eigenvector.munit());
fullcov
}

}
/// Translates subscripts to a 1d vector, i.e. natural numbers, to a pair of
/// (row,column) coordinates within a lower/upper triangular matrix.
/// Enables memory efficient representation of triangular matrices as one flat vector.
Expand All @@ -109,6 +104,20 @@ impl TriangMat {
let column = s - row * (row + 1) / 2; // subtracting the last triangular number (of whole rows)
(row, column)
}
/// Project symmetric/antisymmetric triangmat to a smaller one of the same kind,
/// into a subspace specified by an ascending index of dimensions.
/// Deletes all rows and columns of the missing dimensions.
pub fn project(&self, index: &[usize]) -> Self {
let mut res = Vec::with_capacity(sumn(index.len()));
for &row_idx in index {
let row = self.row(row_idx);
for &column_idx in index {
if column_idx > row.len() { break; };
res.push(row[column_idx]);
};
};
TriangMat { kind:self.kind, data: res }
}

/// Extract one row from TriangMat
pub fn row(&self, r: usize) -> Vec<f64> {
Expand Down Expand Up @@ -290,7 +299,7 @@ impl TriangMat {
{
let u = self.to_full();
let mut qm = m.iter().map(|mvec| mvec.tof64()).collect::<Vec<Vec<f64>>>();
for uvec in u.iter().take(self.rows()) {
for uvec in u.iter().take(self.dim()) {
qm.iter_mut()
.for_each(|qvec| *qvec = uvec.house_reflect::<f64>(qvec))
}
Expand Down
1 change: 1 addition & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ fn triangmat() -> Result<(), RE> {
// let transppt = pts.transpose();
let cov = pts.covar(&pts.par_gmedian(EPS))?;
println!("Comediance matrix:\n{cov}");
println!("Projected to subspace given by [0,2,4,6,9]:\n{}",cov.project(&[0,2,4,6,9]));
let chol = cov.cholesky()?;
println!("Cholesky L matrix:\n{chol}");
println!("Eigenvalues by Cholesky decomposition:\n{}",
Expand Down

0 comments on commit 7268df8

Please sign in to comment.