Skip to content

utils.svd_flip breaks on rectangular matrix #732

@eric-czech

Description

@eric-czech

Is there a fundamental reason that this shouldn't work?

import dask.array as da
from dask_ml.utils import svd_flip

# Run svd on a short-fat array with a single chunk
x = da.random.random(size=(100, 1000)).rechunk((-1, -1))
u, s, v = da.linalg.svd(x)
u, v = svd_flip(u, v)
u.compute()
...
/opt/conda/lib/python3.7/site-packages/dask/core.py in _execute_task(arg, cache, dsk)
    119         # temporaries by their reference count and can execute certain
    120         # operations in-place.
--> 121         return func(*(_execute_task(a, cache) for a in args))
    122     elif not ishashable(arg):
    123         return arg

/opt/conda/lib/python3.7/site-packages/dask_ml/utils.py in _svd_flip_copy(x, y, u_based_decision)
     31         return skm.svd_flip(x, y, u_based_decision=u_based_decision)
     32     except ValueError:
---> 33         return skm.svd_flip(x.copy(), y.copy(), u_based_decision=u_based_decision)
     34 
     35 

/opt/conda/lib/python3.7/site-packages/sklearn/utils/extmath.py in svd_flip(u, v, u_based_decision)
    533         signs = np.sign(u[max_abs_cols, range(u.shape[1])])
    534         u *= signs
--> 535         v *= signs[:, np.newaxis]
    536     else:
    537         # rows of v, columns of u

ValueError: operands could not be broadcast together with shapes (1000,1000) (100,1) (1000,1000)

Environment:

  • Dask version: 2.21.0
  • Python version: 3.7
  • Operating System: linux
  • Install method (conda, pip, source): conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions