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

Commit dc1bd68

Browse files
committed
Fix a few warnings and add new macro to simplify tests.
1 parent 9c466dc commit dc1bd68

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/Simulation/qdk_sim_rs/src/c_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ pub extern "C" fn get_noise_model(sim_id: usize, noise_model_json: *mut *const c
329329
as_capi_err(|| {
330330
let state = STATE
331331
.lock()
332-
.map_err(|e| {
332+
.map_err(|_| {
333333
// Note that as per https://github.com/dtolnay/anyhow/issues/81#issuecomment-609247231,
334334
// common practice is for poison errors to indicate that the containing thread
335335
// has been irrevocably corrupted and must panic.

src/Simulation/qdk_sim_rs/src/linalg/decompositions/lu.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ mod tests {
214214
use ndarray::{array, Array2, OwnedRepr};
215215

216216
use crate::{
217+
c64,
217218
error::QdkSimError,
218219
linalg::decompositions::{LUDecomposable, LU},
219220
};
@@ -260,9 +261,9 @@ mod tests {
260261
// [ 0. +0.j , 0. +0.j ,
261262
// -2.26666667-1.13333333j]]))
262263
let mtx: Array2<c64> = array![
263-
[c64::new(-1.0, 0.0), c64::new(0.0, 1.0), c64::new(-2.0, 0.0)],
264-
[c64::new(3.0, 0.0), c64::new(0.0, 0.0), c64::new(0.0, -4.0)],
265-
[c64::new(-1.0, 0.0), c64::new(5.0, 0.0), c64::new(-1.0, 0.0)]
264+
[c64!(-1.0), c64!(1.0 i), c64!(-2.0)],
265+
[c64!(3.0), c64!(0.0), c64!(-4.0 i)],
266+
[c64!(-1.0), c64!(5.0), c64!(-1.0)]
266267
];
267268
let lu: LU<c64, OwnedRepr<c64>> = mtx.lu()?;
268269

src/Simulation/qdk_sim_rs/src/linalg/inv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cauchy::Scalar;
2-
use ndarray::{Array1, Array2, Data, OwnedRepr, RawData};
2+
use ndarray::{Array1, Array2, OwnedRepr};
33

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

src/Simulation/qdk_sim_rs/src/utils.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,31 @@ pub fn phase_product(row1: &ArrayView1<bool>, row2: &ArrayView1<bool>) -> bool {
123123

124124
((if r1 { 2 } else { 0 }) + (if r2 { 2 } else { 0 }) + acc) % 4 == 2
125125
}
126+
127+
/// Macro for quickly declaring complex numbers of type [`cauchy::c64`].
128+
///
129+
/// # Example
130+
/// ```
131+
/// # use qdk_sim::c64;
132+
/// # use cauchy::c64;
133+
/// let re_unit = c64!(1.0);
134+
/// assert_eq!(re_unit, c64::new(1.0, 0.0));
135+
///
136+
/// let im_unit = c64!(1.0 i);
137+
/// assert_eq!(im_unit, c64::new(0.0, 1.0));
138+
///
139+
/// let z = c64!(1.0 + 2.0 i);
140+
/// assert_eq!(z, c64::new(1.0, 2.0));
141+
/// ```
142+
#[macro_export]
143+
macro_rules! c64 {
144+
($re:literal) => {
145+
c64::new($re, 0.0)
146+
};
147+
($re:literal + $im:literal i) => {
148+
c64::new($re, $im)
149+
};
150+
($im:literal i) => {
151+
c64::new(0.0, $im)
152+
};
153+
}

0 commit comments

Comments
 (0)