diff options
| author | hachem <im@hachem.wtf> | 2026-09-14 12:20:52 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-14 12:20:52 +0200 |
| commit | ee14ad272e68d9363202d7f668e0b20302827209 (patch) | |
| tree | 88dd1012ad7f9d6ac7abeb7562dac2194794b823 /src/core/custom_gate.c | |
| parent | ae07aab1442a45bbddb79e066f15eaf252a4254a (diff) | |
feat: simd + testing + formatting
Diffstat (limited to 'src/core/custom_gate.c')
| -rw-r--r-- | src/core/custom_gate.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/core/custom_gate.c b/src/core/custom_gate.c index 3b3a7e2..dd41635 100644 --- a/src/core/custom_gate.c +++ b/src/core/custom_gate.c @@ -7,7 +7,7 @@ #include "core/gates.h" -struct PsiCustomGate psi_new_custom_gate_from_matrix(const char *name, struct PsiMatrix matrix) +struct PsiCustomGate psi_new_custom_gate_from_matrix(const char* name, struct PsiMatrix matrix) { assert(matrix.rows == matrix.cols); @@ -27,9 +27,11 @@ struct PsiCustomGate psi_new_custom_gate_from_matrix(const char *name, struct Ps return gate; } -struct PsiCustomGate psi_new_custom_gate_from_composite(const char *name, size_t num_qubits, const struct PsiCompositeGateOp *ops, size_t op_count) +struct PsiCustomGate psi_new_custom_gate_from_composite(const char* name, size_t num_qubits, + const struct PsiCompositeGateOp* ops, + size_t op_count) { - struct PsiCompositeGateOp *owned = malloc(op_count * sizeof(struct PsiCompositeGateOp)); + struct PsiCompositeGateOp* owned = malloc(op_count * sizeof(struct PsiCompositeGateOp)); assert(owned != NULL || op_count == 0); if (op_count > 0) @@ -45,7 +47,7 @@ struct PsiCustomGate psi_new_custom_gate_from_composite(const char *name, size_t return gate; } -void psi_free_custom_gate(struct PsiCustomGate *gate) +void psi_free_custom_gate(struct PsiCustomGate* gate) { if (gate->kind == PSI_CUSTOM_GATE_MATRIX) { @@ -78,7 +80,7 @@ static struct PsiQuantumGate op_gate(enum PsiCompositeOp op) return psi_identity_gate(); } -static bool find_target(const size_t *targets, size_t count, size_t q, size_t *pos) +static bool find_target(const size_t* targets, size_t count, size_t q, size_t* pos) { for (size_t i = 0; i < count; i++) if (targets[i] == q) @@ -90,7 +92,8 @@ static bool find_target(const size_t *targets, size_t count, size_t q, size_t *p return false; } -static struct PsiMatrix build_full_operator(struct PsiMatrix gate_matrix, const size_t *targets, size_t num_gate_qubits, size_t total_qubits) +static struct PsiMatrix build_full_operator(struct PsiMatrix gate_matrix, const size_t* targets, + size_t num_gate_qubits, size_t total_qubits) { size_t dim = (size_t)1 << total_qubits; size_t gate_dim = gate_matrix.rows; @@ -139,7 +142,8 @@ static struct PsiMatrix compute_composite_matrix(struct PsiCustomGate gate) struct PsiCompositeGateOp step = gate.definition.composite.ops[i]; struct PsiQuantumGate g = op_gate(step.op); - struct PsiMatrix full = build_full_operator(g.matrix, step.targets, step.target_count, gate.num_qubits); + struct PsiMatrix full = + build_full_operator(g.matrix, step.targets, step.target_count, gate.num_qubits); struct PsiMatrix next = psi_dot_matrix(full, result); psi_free_matrix(&full); @@ -154,7 +158,8 @@ static struct PsiMatrix compute_composite_matrix(struct PsiCustomGate gate) struct PsiQuantumGate psi_to_quantum_gate(struct PsiCustomGate gate) { if (gate.kind == PSI_CUSTOM_GATE_MATRIX) - return psi_new_quantum_gate(gate.name, psi_clone_matrix(gate.definition.matrix), gate.num_qubits); + return psi_new_quantum_gate(gate.name, psi_clone_matrix(gate.definition.matrix), + gate.num_qubits); return psi_new_quantum_gate(gate.name, compute_composite_matrix(gate), gate.num_qubits); } |
