mattloper / chumpy

MIT License
195 stars 118 forks source link

ch.linalg.svd not working in stacked mode #19

Open thmoa opened 6 years ago

thmoa commented 6 years ago

From numpy doc:

If a has more than two dimensions, then broadcasting rules apply [...]. This means that SVD is working in “stacked” mode: it iterates over all indices of the first a.ndim - 2 dimensions and for each combination SVD is applied to the last two indices.

https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.svd.html

When calculating the derivatives for SVD chumpy assumes 2D arrays:

line 196 of linalg.py:

result = np.einsum('ik,jk->kij', u, v)

line 214ff of linalg.py

mxsz = max(shp[0], shp[1])
D = np.zeros(mxsz)
D[:_D.size] = _D

The only workaround I see right now is looping over the dimensions outside of SVD (slow).