|
2 | 2 | // Licensed under the MIT License. |
3 | 3 |
|
4 | 4 | namespace Microsoft.Quantum.Arrays { |
| 5 | + open Microsoft.Quantum.Canon; |
5 | 6 |
|
6 | 7 | /// # Summary |
7 | 8 | /// Returns all consecutive subarrays of length `size`. |
@@ -73,4 +74,93 @@ namespace Microsoft.Quantum.Arrays { |
73 | 74 | internal function Prefix<'T>(to : Int, array : 'T[]) : 'T[] { |
74 | 75 | return array[0..to]; |
75 | 76 | } |
| 77 | + |
| 78 | + /// # Summary |
| 79 | + /// Applies an operation windowing over an input register. |
| 80 | + /// |
| 81 | + /// # Input |
| 82 | + /// ## windowLen |
| 83 | + /// The size of each window. |
| 84 | + /// ## op |
| 85 | + /// An operation on a register that will be provided with the current window and its index. |
| 86 | + /// ## register |
| 87 | + /// The register the operation windows over. |
| 88 | + /// |
| 89 | + /// # Example |
| 90 | + /// The example below shows how to use `ApplyToEachWindow` to construct a parity function |
| 91 | + /// ```qsharp |
| 92 | + /// operation Parity(qubits : Qubit[], target : Qubit) : Unit { |
| 93 | + /// ApplyToEachWindow(1, (_, q) => CNOT(q[0], target), qubits); |
| 94 | + /// } |
| 95 | + /// ``` |
| 96 | + /// |
| 97 | + /// # Type Parameters |
| 98 | + /// ## 'T |
| 99 | + /// The type of register elements. |
| 100 | + operation ApplyToEachWindow<'T>(windowLen : Int, op : (Int, 'T[]) => Unit, register : 'T[]) : Unit { |
| 101 | + ApplyToEach(op, Enumerated(Windows(windowLen, register))); |
| 102 | + } |
| 103 | + |
| 104 | + /// # Summary |
| 105 | + /// Applies an operation windowing over an input register. The modifier `A` indicates that the single-qubit operation is adjointable. |
| 106 | + /// |
| 107 | + /// # Input |
| 108 | + /// ## windowLen |
| 109 | + /// The size of each window. |
| 110 | + /// ## op |
| 111 | + /// An operation on a register that will be provided with the current window and its index. |
| 112 | + /// ## register |
| 113 | + /// The register the operation windows over. |
| 114 | + //// |
| 115 | + /// # Type Parameters |
| 116 | + /// ## 'T |
| 117 | + /// The type of register elements. |
| 118 | + /// |
| 119 | + /// # See Also |
| 120 | + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow |
| 121 | + operation ApplyToEachWindowA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj, register : 'T[]) : Unit is Adj { |
| 122 | + ApplyToEachA(op, Enumerated(Windows(windowLen, register))); |
| 123 | + } |
| 124 | + |
| 125 | + /// # Summary |
| 126 | + /// Applies an operation windowing over an input register. The modifier `C` indicates that the single-qubit operation is controllable. |
| 127 | + /// |
| 128 | + /// # Input |
| 129 | + /// ## windowLen |
| 130 | + /// The size of each window. |
| 131 | + /// ## op |
| 132 | + /// An operation on a register that will be provided with the current window and its index. |
| 133 | + /// ## register |
| 134 | + /// The register the operation windows over. |
| 135 | + //// |
| 136 | + /// # Type Parameters |
| 137 | + /// ## 'T |
| 138 | + /// The type of register elements. |
| 139 | + /// |
| 140 | + /// # See Also |
| 141 | + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow |
| 142 | + operation ApplyToEachWindowC<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Ctl, register : 'T[]) : Unit is Ctl { |
| 143 | + ApplyToEachC(op, Enumerated(Windows(windowLen, register))); |
| 144 | + } |
| 145 | + |
| 146 | + /// # Summary |
| 147 | + /// Applies an operation windowing over an input register. The modifier `CA` indicates that the single-qubit operation is controllable and adjointable. |
| 148 | + /// |
| 149 | + /// # Input |
| 150 | + /// ## windowLen |
| 151 | + /// The size of each window. |
| 152 | + /// ## op |
| 153 | + /// An operation on a register that will be provided with the current window and its index. |
| 154 | + /// ## register |
| 155 | + /// The register the operation windows over. |
| 156 | + //// |
| 157 | + /// # Type Parameters |
| 158 | + /// ## 'T |
| 159 | + /// The type of register elements. |
| 160 | + /// |
| 161 | + /// # See Also |
| 162 | + /// - Microsoft.Quantum.Arrays.ApplyToEachWindow |
| 163 | + operation ApplyToEachWindowCA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj + Ctl, register : 'T[]) : Unit is Adj + Ctl { |
| 164 | + ApplyToEachCA(op, Enumerated(Windows(windowLen, register))); |
| 165 | + } |
76 | 166 | } |
0 commit comments