Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Fix a few warnings and add new macro to simplify tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranade committed Apr 1, 2022
1 parent 9c466dc commit dc1bd68
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Simulation/qdk_sim_rs/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ pub extern "C" fn get_noise_model(sim_id: usize, noise_model_json: *mut *const c
as_capi_err(|| {
let state = STATE
.lock()
.map_err(|e| {
.map_err(|_| {
// Note that as per https://github.com/dtolnay/anyhow/issues/81#issuecomment-609247231,
// common practice is for poison errors to indicate that the containing thread
// has been irrevocably corrupted and must panic.
Expand Down
7 changes: 4 additions & 3 deletions src/Simulation/qdk_sim_rs/src/linalg/decompositions/lu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ mod tests {
use ndarray::{array, Array2, OwnedRepr};

use crate::{
c64,
error::QdkSimError,
linalg::decompositions::{LUDecomposable, LU},
};
Expand Down Expand Up @@ -260,9 +261,9 @@ mod tests {
// [ 0. +0.j , 0. +0.j ,
// -2.26666667-1.13333333j]]))
let mtx: Array2<c64> = array![
[c64::new(-1.0, 0.0), c64::new(0.0, 1.0), c64::new(-2.0, 0.0)],
[c64::new(3.0, 0.0), c64::new(0.0, 0.0), c64::new(0.0, -4.0)],
[c64::new(-1.0, 0.0), c64::new(5.0, 0.0), c64::new(-1.0, 0.0)]
[c64!(-1.0), c64!(1.0 i), c64!(-2.0)],
[c64!(3.0), c64!(0.0), c64!(-4.0 i)],
[c64!(-1.0), c64!(5.0), c64!(-1.0)]
];
let lu: LU<c64, OwnedRepr<c64>> = mtx.lu()?;

Expand Down
2 changes: 1 addition & 1 deletion src/Simulation/qdk_sim_rs/src/linalg/inv.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cauchy::Scalar;
use ndarray::{Array1, Array2, Data, OwnedRepr, RawData};
use ndarray::{Array1, Array2, OwnedRepr};

use crate::linalg::decompositions::{LUDecomposable, LUDecomposition};

Expand Down
28 changes: 28 additions & 0 deletions src/Simulation/qdk_sim_rs/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,31 @@ pub fn phase_product(row1: &ArrayView1<bool>, row2: &ArrayView1<bool>) -> bool {

((if r1 { 2 } else { 0 }) + (if r2 { 2 } else { 0 }) + acc) % 4 == 2
}

/// Macro for quickly declaring complex numbers of type [`cauchy::c64`].
///
/// # Example
/// ```
/// # use qdk_sim::c64;
/// # use cauchy::c64;
/// let re_unit = c64!(1.0);
/// assert_eq!(re_unit, c64::new(1.0, 0.0));
///
/// let im_unit = c64!(1.0 i);
/// assert_eq!(im_unit, c64::new(0.0, 1.0));
///
/// let z = c64!(1.0 + 2.0 i);
/// assert_eq!(z, c64::new(1.0, 2.0));
/// ```
#[macro_export]
macro_rules! c64 {
($re:literal) => {
c64::new($re, 0.0)
};
($re:literal + $im:literal i) => {
c64::new($re, $im)
};
($im:literal i) => {
c64::new(0.0, $im)
};
}

0 comments on commit dc1bd68

Please sign in to comment.