Skip to content

[ENHANCEMENT] Ignore extraneous dimension names in qr/svd #22

@mtfishman

Description

@mtfishman

A common code pattern in ITensors.jl is analogous to the following:

using NamedDimsArrays: nameddims
a = nameddims(randn(2, 2), ("i", "j"))
b = nameddims(randn(2, 2), ("j", "k"))
q, r = qr(b, dimnames(a))

This fails right now because qr(::AbstractNamedDimsArray, codomain_names) is strict about the names that are input as the codomain names in the factorization, and dimnames(a) contains the name "i" which isn't a dimension name of b.

One can do:

q, r = qr(b, intersect(dimnames(b), dimnames(a)))

but that is a bit annoying to write which is why we automated it in ITensors.jl. We could have a keyword argument that toggles between the two:

 # errors
q, r = qr(b, intersect(dimnames(b), dimnames(a)); strict=true)

# no error, equaivalent to `qr(b, intersect(dimnames(b), dimnames(a)))`, probably the default
q, r = qr(b, dimnames(a); strict=false)

Additionally, I think passing both the codomain and domain names should be strict, i.e.:

q, r = qr(b, dimnames(a), ("j",)) # errors
q, r = qr(b, ("i",), ("j",)) # works
q, r = qr(b, intersect(dimnames(b), dimnames(a)), setdiff(dimnames(b), dimnames(a))) # works

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions