PySparQ.pysparq.algorithms.qram_utils

Classical helper functions for building QRAM circuits.

Attributes

PI

Pi constant matching the C++ constexpr double pi.

Functions

column_flatten(→ list[float])

Transpose a row-major square matrix into its column-major representation.

create_qram_utils_demo(→ str)

Return a demo script string showing typical usage of this module.

get_complement(→ int)

Inverse two's complement: sign-extend an unsigned value to a signed integer.

make_complement(→ int)

Convert a signed integer to its two's-complement representation.

make_func(→ list[complex])

Compute a 2x2 rotation matrix from a rational register value.

make_func_inv(→ list[complex])

Compute the inverse 2x2 rotation matrix from a rational register value.

make_vector_tree(→ list[int])

Build a binary tree for QRAM circuits from leaf-distribution data.

pow2(→ int)

Return 2**n via a left shift, matching basic.h semantics.

scale_and_convert_vector(→ list[int])

Scale floating-point values and convert to two's-complement integers.

Module Contents

PySparQ.pysparq.algorithms.qram_utils.column_flatten(row_vec: list[float]) → list[float][源代码]

Transpose a row-major square matrix into its column-major representation.

PySparQ.pysparq.algorithms.qram_utils.create_qram_utils_demo() → str[源代码]

Return a demo script string showing typical usage of this module.

PySparQ.pysparq.algorithms.qram_utils.get_complement(data: int, data_sz: int) → int[源代码]

Inverse two's complement: sign-extend an unsigned value to a signed integer.

PySparQ.pysparq.algorithms.qram_utils.make_complement(data: int, data_sz: int) → int[源代码]

Convert a signed integer to its two's-complement representation.

PySparQ.pysparq.algorithms.qram_utils.make_func(value: int, n_digit: int) → list[complex][源代码]

Compute a 2x2 rotation matrix from a rational register value.

PySparQ.pysparq.algorithms.qram_utils.make_func_inv(value: int, n_digit: int) → list[complex][源代码]

Compute the inverse 2x2 rotation matrix from a rational register value.

PySparQ.pysparq.algorithms.qram_utils.make_vector_tree(dist: list[int], data_size: int) → list[int][源代码]

Build a binary tree for QRAM circuits from leaf-distribution data.

PySparQ.pysparq.algorithms.qram_utils.pow2(n: int) → int[源代码]

Return 2**n via a left shift, matching basic.h semantics.

PySparQ.pysparq.algorithms.qram_utils.scale_and_convert_vector(input_vec: list[float] | numpy.ndarray, exponent: int, data_size: int, from_matrix: bool = ...) → list[int][源代码]

Scale floating-point values and convert to two's-complement integers.

PySparQ.pysparq.algorithms.qram_utils.PI: float[源代码]

Pi constant matching the C++ constexpr double pi.