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

Commit b60d691

Browse files
committed
Addressing feedback.
1 parent 9b05a04 commit b60d691

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/Simulation/qdk_sim_rs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ TODO
145145
- Too many APIs `panic!` or `unwrap`, and need replaced with `Result` returns instead.
146146

147147
# Crate features
148+
<!-- Note that this section is filled in automatically by document-features. -->

src/Simulation/qdk_sim_rs/src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use thiserror::Error;
1111
/// Represents errors that can occur during linear algebra operations.
1212
#[derive(Debug, Diagnostic, Error)]
1313
pub enum QdkSimError {
14-
// NB: As a design note, these should be eliminated before stabilizing the
15-
// API for this simulator crate.
14+
// NB: As a design note, please consider if a more specific error is better
15+
// suited for your usecase before returning `MiscError`.
1616
/// Raised on miscellaneous errors.
1717
#[error("{0}")]
1818
#[diagnostic(code(qdk_sim::other))]

src/Simulation/qdk_sim_rs/src/linalg/array_ext.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ where
7676
D: Dimension + RemoveAxis,
7777
{
7878
fn swap_index_axis(&mut self, axis: Axis, idx_source: usize, idx_dest: usize) {
79-
// TODO: Avoid copying both; this is needed currently to avoid mutably
80-
// borrowing something which has an outstanding immutable
81-
// borrow.
79+
// TODO[perf]: Avoid copying both; this is needed currently to avoid mutably
80+
// borrowing something which has an outstanding immutable
81+
// borrow.
8282
let source = self.index_axis(axis, idx_source).clone().to_owned();
8383
let dest = self.index_axis(axis, idx_dest).clone().to_owned();
8484
self.index_axis_mut(axis, idx_source).assign(&dest);
@@ -88,7 +88,7 @@ where
8888

8989
#[cfg(test)]
9090
mod tests {
91-
use super::ArrayBaseMatrixExt;
91+
use super::{ArrayBaseMatrixExt, ArrayBaseRemoveAxisExt};
9292
use ndarray::{array, Array2};
9393

9494
#[test]
@@ -110,4 +110,20 @@ mod tests {
110110
array![[6.0, 0.0, 0.0], [2.0, 12.0, 0.0], [4.0, 15.0, 3.0]]
111111
);
112112
}
113+
114+
#[test]
115+
fn swap_index_axis_swaps_rows_correctly() {
116+
let mut mtx = array![[6.0, 18.0, 3.0], [2.0, 12.0, 1.0], [4.0, 15.0, 3.0]];
117+
mtx.swap_index_axis(ndarray::Axis(0), 1, 2);
118+
let expected = array![[6.0, 18.0, 3.0], [4.0, 15.0, 3.0], [2.0, 12.0, 1.0]];
119+
assert_eq!(mtx, expected);
120+
}
121+
122+
#[test]
123+
fn swap_index_axis_swaps_columns_correctly() {
124+
let mut mtx = array![[6.0, 18.0, 3.0], [2.0, 12.0, 1.0], [4.0, 15.0, 3.0]];
125+
mtx.swap_index_axis(ndarray::Axis(1), 1, 2);
126+
let expected = array![[6.0, 3.0, 18.0], [2.0, 1.0, 12.0], [4.0, 3.0, 15.0]];
127+
assert_eq!(mtx, expected);
128+
}
113129
}

0 commit comments

Comments
 (0)