Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Simulation/QsharpCore/Arrays/Empty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using System;
using Microsoft.Quantum.Simulation.Core;

namespace Microsoft.Quantum.Arrays
{
public partial class EmptyArray<__TElement__>
{
public class Native : EmptyArray<__TElement__>
{
public Native(IOperationFactory m) : base(m) { }
public override Func<QVoid, IQArray<__TElement__>> __Body__ => _ =>
new QArray<__TElement__>();
}
}

}
24 changes: 24 additions & 0 deletions src/Simulation/QsharpCore/Arrays/Empty.qs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Arrays {

/// # Summary
/// Returns the empty array of a given type.
///
/// # Type Parameters
/// ## 'TElement
/// The type of elements of the array.
///
/// # Output
/// The empty array.
///
/// # Example
/// ```Q#
/// let empty = EmptyArray<Int>();
/// ```
function EmptyArray<'TElement>() : 'TElement[] {
body intrinsic;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Arrays {
open Microsoft.Quantum.Diagnostics;

/// # Summary
/// Checks that empty arrays are indeed empty.
@Test("QuantumSimulator")
@Test("ToffoliSimulator")
function EmptyArraysAreEmpty() : Unit {
Fact(
Length(EmptyArray<Int>()) == 0,
"Empty array of type Int[] was not actually empty."
);
Fact(
Length(EmptyArray<(Double, Pauli[])>()) == 0,
"Empty array of type (Double, Pauli[])[] was not actually empty."
);
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Tests {
open Microsoft.Quantum.Intrinsic;
open Microsoft.Quantum.Canon;
Expand Down