Skip to content

Dask Array's diag supporting diagonal selection #2726

Closed

Description

@jakirkham

Would be nice if Dask Array's diag supported the k value to allow selection of the diagonal as NumPy's implementation does. It seems like Dask Array's API docs suggest diag does support k, but the code does not allow for this option.

def diag(v):

Activity

  1. added
    good second issue
    on Oct 24, 2018
  2. jakirkham commented on Feb 9, 2019

    @jakirkham
    MemberAuthor

    It might make sense to rewrite diag to use diagonal after PR ( #4431 ) is accepted. This would be a way to solve this problem and cutdown on code as well.

  3. lightsighter commented on Mar 9, 2019

    @lightsighter

    It's worth pointing out this feature is broken in both directions. You also can't make a dask 2-D array from a vector on k!=0 diagonal. Support for da.diagonal doesn't help at all in this case as da.diagonal only extracts diagonals from 2-D arrays. Here's a use case to reproduce the problem:

    import dask.array as da
    v = da.random.uniform(size=100,chunks=50)
    A = da.diag(v,k=1)

    which yields the following error:

    TypeError: diag() got an unexpected keyword argument 'k'

    At a minimum the documentation should be updated to reflect that you don't support the 'k' keyword argument. Currently the documentation says that it is supported.
    http://docs.dask.org/en/latest/array-api.html#dask.array.diag

  4. mrocklin commented on Mar 9, 2019

    @mrocklin
    Member
  5. TAdeJong commented on May 20, 2019

    @TAdeJong
    Contributor

    I am working on a pull request on this using #4431 for the diagonal extraction case. WIP though, as I was surprised by the $(n+k)*(n+k)$ output of np.diag(np.ones(n), k).
    I also want to have a look into cleaning up the shared but different code in da.triu, da.tril and da.diag.

  6. jakirkham commented on May 20, 2019

    @jakirkham
    MemberAuthor

    Cool, thanks for working on this. Please let us know if you need pointers or would like someone to take a look.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    arraygood second issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions