Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit 888d2bf

Browse files
committed
Update ApplyWindowed to be more idiomatic
See comment on #602 by @cgranade
1 parent 3f87f06 commit 888d2bf

File tree

1 file changed

+63
-11
lines changed

1 file changed

+63
-11
lines changed

Standard/src/Arrays/Windows.qs

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,74 @@ namespace Microsoft.Quantum.Arrays {
7575
}
7676

7777
/// # Summary
78-
/// Applies an operation windowing over input but with constant target qubits.
78+
/// Applies an operation windowing over input registers.
7979
///
8080
/// # Input
8181
/// ## windowLen
8282
/// The size of each window
8383
/// ## op
84-
/// An operation with three arguments, one index, controls, and target. When applied it will be supplied with a windowed component of the `qubits` parameter, the `target` qubits (constant) and an index of the current window
85-
/// ## qubits
86-
/// The qubits the operation windows over
87-
/// ## target
88-
/// The target provided to each windowed operation
89-
operation ApplyWindowed(windowLen : Int, op : (Int, Qubit[], Qubit[]) => Unit, qubits : Qubit[], target : Qubit[]) : Unit {
90-
let windows = Windows(windowLen, qubits); // Create windows of non-target qubits
91-
for (i, window) in Enumerated(windows) {
92-
op(i, window, target);
93-
}
84+
/// An operation on registers that will be provided with the current window and its index
85+
/// ## registers
86+
/// The registers the operation windows over
87+
////
88+
/// # Type Parameters
89+
/// ## 'T
90+
/// The type of registers
91+
operation ApplyWindowed<'T>(windowLen : Int, op : (Int, 'T[]) => Unit, register : 'T[]) : Unit {
92+
ApplyToEach(op, Enumerated(Windows(windowLen, register)));
93+
}
94+
95+
/// # Summary
96+
/// Applies an operation windowing over input registers. The modifier `A` indicates that the single-qubit operation is adjointable.
97+
///
98+
/// # Input
99+
/// ## windowLen
100+
/// The size of each window
101+
/// ## op
102+
/// An operation on registers that will be provided with the current window and its index
103+
/// ## registers
104+
/// The registers the operation windows over
105+
////
106+
/// # Type Parameters
107+
/// ## 'T
108+
/// The type of registers
109+
operation ApplyWindowedA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj, register : 'T[]) : Unit is Adj {
110+
ApplyToEachA(op, Enumerated(Windows(windowLen, register)));
111+
}
112+
113+
/// # Summary
114+
/// Applies an operation windowing over input registers. The modifier `C` indicates that the single-qubit operation is controllable.
115+
///
116+
/// # Input
117+
/// ## windowLen
118+
/// The size of each window
119+
/// ## op
120+
/// An operation on registers that will be provided with the current window and its index
121+
/// ## registers
122+
/// The registers the operation windows over
123+
////
124+
/// # Type Parameters
125+
/// ## 'T
126+
/// The type of registers
127+
operation ApplyWindowedC<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Ctl, register : 'T[]) : Unit is Ctl {
128+
ApplyToEachC(op, Enumerated(Windows(windowLen, register)));
94129
}
95130

131+
/// # Summary
132+
/// Applies an operation windowing over input registers. The modifier `CA` indicates that the single-qubit operation is controllable and adjointable.
133+
///
134+
/// # Input
135+
/// ## windowLen
136+
/// The size of each window
137+
/// ## op
138+
/// An operation on registers that will be provided with the current window and its index
139+
/// ## registers
140+
/// The registers the operation windows over
141+
////
142+
/// # Type Parameters
143+
/// ## 'T
144+
/// The type of registers
145+
operation ApplyWindowedCA<'T>(windowLen : Int, op : (Int, 'T[]) => Unit is Adj + Ctl, register : 'T[]) : Unit is Adj + Ctl {
146+
ApplyToEachCA(op, Enumerated(Windows(windowLen, register)));
147+
}
96148
}

0 commit comments

Comments
 (0)