Struct quest_bind::ComplexMatrixN
source · pub struct ComplexMatrixN(_);
Implementations§
source§impl ComplexMatrixN
impl ComplexMatrixN
sourcepub fn try_new(num_qubits: i32) -> Result<Self, QuestError>
pub fn try_new(num_qubits: i32) -> Result<Self, QuestError>
Allocate dynamic memory for a square complex matrix of any size.
Examples
let mtr = ComplexMatrixN::try_new(3).unwrap();
See QuEST API for more information.
Errors
Returns QuestError::InvalidQuESTInputError
on failure. This is an exception thrown by QuEST
.
sourcepub fn num_qubits(&self) -> i32
pub fn num_qubits(&self) -> i32
Get number of qubits this operators acts on.
Examples
let mtr = ComplexMatrixN::try_new(3).unwrap();
assert_eq!(mtr.num_qubits(), 3);
sourcepub fn row_real_as_slice(&self, i: usize) -> &[Qreal]
pub fn row_real_as_slice(&self, i: usize) -> &[Qreal]
Get the real part of the i
th row of the matrix as shared slice.
Examples
let num_qubits = 2;
let mtr = &mut ComplexMatrixN::try_new(num_qubits).unwrap();
init_complex_matrix_n(
mtr,
&[
&[111., 112., 113., 114.],
&[115., 116., 117., 118.],
&[119., 120., 121., 122.],
&[123., 124., 125., 126.],
],
&[
&[211., 212., 213., 214.],
&[215., 216., 217., 218.],
&[219., 220., 221., 222.],
&[223., 224., 225., 226.],
],
)
.unwrap();
let i = 3;
assert!(i < 1 << num_qubits);
let row = mtr.row_real_as_slice(i);
assert_eq!(row, &[123., 124., 125., 126.]);
Panics
This function will panic if i>= 2.pow(1<< num_qubits), where
num_qubits` is the number of qubits the matrix was initialized
with.
sourcepub fn row_real_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]
pub fn row_real_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]
Get the real part of the i
th row of the matrix as mutable slice.
Examples
let num_qubits = 2;
let mtr = &mut ComplexMatrixN::try_new(num_qubits).unwrap();
init_complex_matrix_n(
mtr,
&[
&[111., 112., 113., 114.],
&[115., 116., 117., 118.],
&[119., 120., 121., 122.],
&[123., 124., 125., 126.],
],
&[
&[211., 212., 213., 214.],
&[215., 216., 217., 218.],
&[219., 220., 221., 222.],
&[223., 224., 225., 226.],
],
)
.unwrap();
let i = 3;
assert!(i < 1 << num_qubits);
let row = mtr.row_real_as_mut_slice(i);
assert_eq!(row, &[123., 124., 125., 126.]);
Panics
This function will panic if i>= 2.pow(1<< num_qubits), where
num_qubits` is the number of qubits the matrix was initialized
with.
sourcepub fn row_imag_as_slice(&self, i: usize) -> &[Qreal]
pub fn row_imag_as_slice(&self, i: usize) -> &[Qreal]
Get the imaginary part of the i
th row of the matrix as shared slice.
Examples
let num_qubits = 2;
let mtr = &mut ComplexMatrixN::try_new(num_qubits).unwrap();
init_complex_matrix_n(
mtr,
&[
&[111., 112., 113., 114.],
&[115., 116., 117., 118.],
&[119., 120., 121., 122.],
&[123., 124., 125., 126.],
],
&[
&[211., 212., 213., 214.],
&[215., 216., 217., 218.],
&[219., 220., 221., 222.],
&[223., 224., 225., 226.],
],
)
.unwrap();
let i = 3;
assert!(i < 1 << num_qubits);
let row = mtr.row_imag_as_slice(i);
assert_eq!(row, &[223., 224., 225., 226.]);
Panics
This function will panic if i>= 2.pow(1<< num_qubits), where
num_qubits` is the number of qubits the matrix was initialized
with.
sourcepub fn row_imag_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]
pub fn row_imag_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]
Get the imaginary part of the i
th row of the matrix as mutable slice.
Examples
let num_qubits = 2;
let mtr = &mut ComplexMatrixN::try_new(num_qubits).unwrap();
init_complex_matrix_n(
mtr,
&[
&[111., 112., 113., 114.],
&[115., 116., 117., 118.],
&[119., 120., 121., 122.],
&[123., 124., 125., 126.],
],
&[
&[211., 212., 213., 214.],
&[215., 216., 217., 218.],
&[219., 220., 221., 222.],
&[223., 224., 225., 226.],
],
)
.unwrap();
let i = 3;
assert!(i < 1 << num_qubits);
let row = mtr.row_imag_as_mut_slice(i);
assert_eq!(row, &[223., 224., 225., 226.]);
Panics
This function will panic if i>= 2.pow(1<< num_qubits), where
num_qubits` is the number of qubits the matrix was initialized
with.