From a84b6394209e37620e45155a25b3755b38ba8515 Mon Sep 17 00:00:00 2001 From: hachem Date: Fri, 20 Sep 2024 09:25:19 +0200 Subject: basic quantum gate setup and quantum registers --- libmu/src/maths/matrix.rs | 3 ++- libmu/src/maths/vector.rs | 17 ++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'libmu/src/maths') diff --git a/libmu/src/maths/matrix.rs b/libmu/src/maths/matrix.rs index 9932895..388f858 100644 --- a/libmu/src/maths/matrix.rs +++ b/libmu/src/maths/matrix.rs @@ -24,6 +24,7 @@ macro_rules! matrix { }}; } +#[derive(Clone)] pub struct Matrix { pub data: Vec, pub rows: usize, @@ -78,7 +79,7 @@ impl Matrix { for l in 0..other.cols { let result_row = i * other.rows + k; let result_col = j * other.cols + l; - result.set(result_row, result_col, self_val * other.get(k, l)) + result.set(result_row, result_col, self_val.clone() * other.get(k, l)); } } } diff --git a/libmu/src/maths/vector.rs b/libmu/src/maths/vector.rs index c97b415..0c13e4c 100644 --- a/libmu/src/maths/vector.rs +++ b/libmu/src/maths/vector.rs @@ -362,14 +362,13 @@ impl fmt::Display for RowVector { impl fmt::Display for ColumnVector { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "[{}]", - self.0 - .iter() - .map(|x| x.to_string()) - .collect::>() - .join(", ") - ) + write!(f, "[")?; + for (i, x) in self.0.iter().enumerate() { + if i > 0 { + write!(f, ",\n ")?; + } + write!(f, "{}", x)?; + } + write!(f, "]") } } -- cgit v1.3