This repository was archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Add C# generation and runtime support for "[value, size = n]" array constructor #507
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6eaac54
Add C# gen for sized array
5ad7f75
Implement QArray.Repeat
ad01b34
Add more array tests
b41ed0f
Add doc comments
d21c679
More efficient array creation
eeb5715
Remove TODO, leave exception type untested
3ac7a0b
Formatting
268c94b
Merge branch 'main' into samarsha/sized-array
bamarsha 5158e4a
Update packages
0474318
Add tests for ref counts in array-of-arrays
6fe98bf
Capture value expression
e7bdfd9
Undo QscVerbosity
51f1aaf
Clean up QArrayInner.Extend
588d499
Increment ref count N times
71102e6
Add comment about exception type
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../QCTraceSimulator.Tests/Tests.Microsoft.Quantum.Simulation.QCTraceSimulatorRuntime.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/QSharpFoundation/Microsoft.Quantum.QSharp.Foundation.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Quantum.Simulation.Simulators.Tests.Circuits { | ||
| open Microsoft.Quantum.Diagnostics; | ||
| open Microsoft.Quantum.Intrinsic; | ||
|
|
||
| operation MapF<'T, 'U>(mapper : ('T -> 'U), source : 'T[]) : 'U[] { | ||
| mutable result = new 'U[Length(source)]; | ||
| for (i in 0 .. Length(source) - 1) { | ||
| let m = mapper(source[i]); | ||
| set result = result w/ i <- m; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| operation LengthTest() : Unit { | ||
| let a1 = [One, Zero]; | ||
| let a2 = [Zero, Zero, Zero]; | ||
|
|
||
| AssertEqual(2, Length(a1)); | ||
| AssertEqual(3, Length(a2)); | ||
|
|
||
| let values = MapF(Length<Result>, [a1, a2]); | ||
| AssertEqual(2, values[0]); | ||
| AssertEqual(3, values[1]); | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function CreateArrayWithPositiveSize() : Unit { | ||
| let xs = [true, size = 3]; | ||
| AssertEqual([true, true, true], xs); | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function CreateArrayWithZeroSize() : Unit { | ||
| let xs = [true, size = 0]; | ||
| AssertEqual(0, Length(xs)); | ||
| } | ||
|
|
||
| function CreateArrayWithNegativeSize() : Bool[] { | ||
| return [true, size = -1]; | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function CreateArrayWithSizeExpression() : Unit { | ||
| let n = 2; | ||
| let xs = [7, size = n + 1]; | ||
| AssertEqual([7, 7, 7], xs); | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function CreateArrayWithValueExpression() : Unit { | ||
| let x = "foo"; | ||
| let xs = [x + "bar", size = 3]; | ||
| AssertEqual(["foobar", "foobar", "foobar"], xs); | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function SizedArrayShouldIncrementArrayItemRefCount() : Unit { | ||
| mutable item = [1]; | ||
| let items = [item, size = 2]; | ||
| set item w/= 0 <- 2; | ||
|
|
||
| AssertEqual([2], item); | ||
| AssertEqual([[1], [1]], items); | ||
| } | ||
|
|
||
| @Test("QuantumSimulator") | ||
| function ArrayOfArraysShouldCopyOnUpdate() : Unit { | ||
| mutable items = [[1], size = 2]; | ||
| set items w/= 0 <- items[0] w/ 0 <- 2; | ||
|
|
||
| AssertEqual([[2], [1]], items); | ||
| } | ||
| } | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/HoneywellExe/HoneywellExe.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/IntrinsicTests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/IonQExe/IonQExe.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/Library with Spaces/Library with Spaces.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/Library1/Library1.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/Library2/Library2.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/QCIExe/QCIExe.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/QSharpExe/QSharpExe.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/TargetedExe/TargetedExe.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/TestProjects/UnitTests/UnitTests.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Tests/Tests.Microsoft.Quantum.Simulators.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Type1.Tests/Tests.Microsoft.Quantum.Simulators.Type1.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Type2.Tests/Tests.Microsoft.Quantum.Simulators.Type2.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Simulation/Simulators.Type3.Tests/Tests.Microsoft.Quantum.Simulators.Type3.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.