Skip to content

Commit

Permalink
Generate an orthogonal matrix and return it
Browse files Browse the repository at this point in the history
  • Loading branch information
tvhong committed Nov 10, 2024
1 parent 890348b commit 991241c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions rs/quantization/src/rabitq_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use ndarray::Array2;
use ndarray_rand::RandomExt;
use ndarray_rand::rand_distr::StandardNormal;
use ndarray_linalg::qr::QR;
use ndarray_linalg::solve::Inverse;
use std::error::Error;

pub struct RabitQBuilder {
dimension: usize,
Expand All @@ -22,25 +24,29 @@ impl RabitQBuilder {

pub fn add(&mut self, data: Vec<f32>) {
self.dataset.push(data);

}

pub fn build(&mut self, _base_directory: String) -> Result<RabitQ, Box<dyn std::error::Error>> {
pub fn build(&mut self, _base_directory: String) -> Result<RabitQ, Box<dyn Error>> {
let q = self.create_orthogonal_matrix(self.dimension)?;

Ok(RabitQ {
p_inv: Vec::new(),
p_inv: q.inv()?,
quantization_codes: Vec::new(),
or_c: Vec::new(),
o_o: Vec::new(),
})
}

pub fn create_orthogonal_matrix(&self, d: usize) {
let _matrix: Array2<f32> = Array2::random((d, d), StandardNormal);
_matrix.qr();
pub fn create_orthogonal_matrix(&self, d: usize) -> Result<Array2<f32>, Box<dyn Error>>{
let matrix: Array2<f32> = Array2::random((d, d), StandardNormal);
let (q, _) = matrix.qr()?;
return Ok(q);
}
}

pub struct RabitQ {
p_inv: Vec<f32>,
p_inv: Array2<f32>,
quantization_codes: Vec<BitVec>,
or_c: Vec<f32>,
o_o: Vec<Vec<f32>>,
Expand Down

0 comments on commit 991241c

Please sign in to comment.