Sitelet https://github.com/microsoft/QuantumLibraries/issues/546
Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Refactor Mapped to avoid use of Default #546

Description

Describe the bug
Default uses deprecated new array syntax to create default and often invalid values for generic types. Because Mapped uses Default to pre-allocate the array being mapped into, it can inadvertently trigger asserts in runtimes that check for valid content on creation of values. We should find a way to refactor Mapped to protect against this.

One possible suggestion for a new implementation (courtesy of Cassandra Granade (@cgranade)):

// pseudocode
function Mapped<'T, 'O>(fn : 'T -> 'O, arr : 'T[]) : 'O {
    if Length(arr) == 0 {
        return [];
    }
    let first = fn(arr[0]);
    mutable retval = [first; size=Length(arr)];
    for idx in 1..Length(arr) - 1{
        set retval w/ idx <- fn(arr[idx]);
    }
    return retval;
}

Related:
microsoft/qsharp-runtime#977
microsoft/qsharp-runtime#975

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Kind-BugSomething isn't workingtrackingThis label will trigger gh-sync to create or update a mirror internal ADO issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions