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 180
New array functions #320
Merged
Merged
New array functions #320
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ce2acf6
Unzipped function.
3e25f94
Incorporating Chris' feedback.
9aad99d
More array functions.
0d6abd2
Rename ColumnVectorAt to ColumnVector.
c5c01ca
Windows function.
200e23a
Apply suggestions from code review
msoeken e5c1a75
Merge branch 'main' into msoeken/arrays
e66855f
Comments from Chris.
abe4fef
Docs.
ba26cad
Use `ElementAt` for `LookupFunction`.
80076fc
Function `Diagonal`.
773e371
Array function `Count`.
8b00cdd
Array function `MappedOverRange`.
9feb23d
Functions `HeadAndRest` and `MostAndTail`.
dfabf8f
Array functions `Flattened` and `FlatMapped`.
87cb1d3
Array function `Prefixes`.
4c82500
Apply suggestions from code review
msoeken 2c63f68
Addressing Chris' comments.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.Quantum.Arrays { | ||
| open Microsoft.Quantum.Diagnostics; | ||
|
|
||
| /// # Summary | ||
| /// Interleaves two arrays of (almost) same size. | ||
| /// | ||
| /// # Description | ||
| /// This function returns the interleaving of two arrays, starting | ||
| /// with the first element from the first array, then the first | ||
| /// element from the second array, and so on. | ||
| /// | ||
| /// The first array must either be | ||
| /// of the same length as the second one, or can have one more element. | ||
| /// | ||
| /// # Type Parameters | ||
| /// ## 'T | ||
| /// The type of each element of `first` and `second`. | ||
| /// | ||
| /// # Input | ||
| /// ## first | ||
| /// The first array to be interleaved. | ||
| /// | ||
| /// ## second | ||
| /// The second array to be interleaved. | ||
| /// | ||
| /// # Output | ||
| /// Interleaved array | ||
| /// | ||
| /// # Example | ||
| /// ```Q# | ||
| /// // same as int1 = [1, -1, 2, -2, 3, -3] | ||
| /// let int1 = Interleaved([1, 2, 3], [-1, -2, -3]) | ||
| /// | ||
| /// // same as int2 = [false, true, false, true, false] | ||
| /// let int2 = Interleaved(ConstantArray(3, false), ConstantArray(2, true)); | ||
| /// ``` | ||
| function Interleaved<'T>(first : 'T[], second : 'T[]) : 'T[] { | ||
| let lFirst = Length(first); | ||
| let lSecond = Length(second); | ||
|
|
||
| Fact(lFirst >= lSecond and lFirst - lSecond <= 1, "Array `first` is either of same size as `second`, or has one more element"); | ||
|
|
||
| return new 'T[lFirst + lSecond] | ||
| w/ 0..2..(lFirst + lSecond - 1) <- first | ||
| w/ 1..2..(lFirst + lSecond - 1) <- second; | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.