pub struct ComplexMatrixN(_);

Implementations§

source§

impl ComplexMatrixN

source

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.

source

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);
source

pub fn row_real_as_slice(&self, i: usize) -> &[Qreal]

Get the real part of the ith 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.

source

pub fn row_real_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]

Get the real part of the ith 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.

source

pub fn row_imag_as_slice(&self, i: usize) -> &[Qreal]

Get the imaginary part of the ith 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.

source

pub fn row_imag_as_mut_slice(&mut self, i: usize) -> &mut [Qreal]

Get the imaginary part of the ith 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.

Trait Implementations§

source§

impl Debug for ComplexMatrixN

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drop for ComplexMatrixN

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.