37 size_t num_qubits = 0;
47 bool assignable = std::tolower(c) != (int)c;
48 switch (std::tolower(c)) {
51 throw std::invalid_argument(
"use uppercase Q for qubits");
72 1ull << num_qubits, 1ull << num_qubits, assignable));
87 throw std::invalid_argument(
"unknown type code encountered");
100 if (expected->assignable && !actual->assignable) {
105 if (actual->type() != expected->type()) {
110 if (
auto expected_real_mat = expected->as_real_matrix()) {
111 auto actual_mat = actual->as_real_matrix();
112 if (expected_real_mat->num_cols >= 0) {
113 if (actual_mat->num_cols != expected_real_mat->num_cols) {
117 if (expected_real_mat->num_rows >= 0) {
118 if (actual_mat->num_rows != expected_real_mat->num_rows) {
122 }
else if (
auto expected_complex_mat = expected->as_complex_matrix()) {
123 auto actual_mat = actual->as_complex_matrix();
124 if (expected_complex_mat->num_cols >= 0) {
125 if (actual_mat->num_cols != expected_complex_mat->num_cols) {
129 if (expected_complex_mat->num_rows >= 0) {
130 if (actual_mat->num_rows != expected_complex_mat->num_rows) {
142 os <<
"empty matrix";
143 }
else if (nrows == 1) {
144 os << ncols <<
"-dimensional vector";
167 }
else if (type->as_bool()) {
169 }
else if (type->as_axis()) {
171 }
else if (type->as_int()) {
173 }
else if (type->as_real()) {
175 }
else if (type->as_complex()) {
177 }
else if (
auto real_mat = type->as_real_matrix()) {
179 mat_size(os, real_mat->num_rows, real_mat->num_cols);
180 }
else if (
auto complex_mat = type->as_complex_matrix()) {
182 mat_size(os, complex_mat->num_rows, complex_mat->num_cols);
183 }
else if (type->as_string()) {
185 }
else if (type->as_json()) {
187 }
else if (type->as_qubit()) {
194 if (type->assignable) {
206 for (
const auto &type : types) {
Type of an integer (signed 64-bit).
Type of a real number (IEEE double).
Types from_spec(const std::string &spec)
Constructs a set of types from a shorthand string representation.
Toplevel namespace with entry points for the new API.
Type of an arbitrary string.
Type of a complex matrix.
Type of one or more qubit references.
Namespace for the "new" cQASM 1.x API.
Type of an axis (x, y, or z).
tree::One< TypeBase > Type
A cQASM type.
Type of a complex number (2x IEEE double).
bool type_check(const Type &expected, const Type &actual)
Returns whether the actual type matches the constraints of the expected type.
tree::Any< TypeBase > Types
Zero or more cQASM types.
std::ostream & operator<<(std::ostream &os, const Type &type)
Stream << overload for a single type.
::tree::signed_size_t signed_size_t
Defines the types of values available within cQASM's type system, as well as some utility functions...