| 1588 | } |
| 1589 | |
| 1590 | void SVD::backSubst( InputArray _w, InputArray _u, InputArray _vt, |
| 1591 | InputArray _rhs, OutputArray _dst ) |
| 1592 | { |
| 1593 | Mat w = _w.getMat(), u = _u.getMat(), vt = _vt.getMat(), rhs = _rhs.getMat(); |
| 1594 | int type = w.type(), esz = (int)w.elemSize(); |
| 1595 | int m = u.rows, n = vt.cols, nb = rhs.data ? rhs.cols : m, nm = std::min(m, n); |
| 1596 | size_t wstep = w.rows == 1 ? (size_t)esz : w.cols == 1 ? (size_t)w.step : (size_t)w.step + esz; |
| 1597 | AutoBuffer<uchar> buffer(nb*sizeof(double) + 16); |
| 1598 | CV_Assert( w.type() == u.type() && u.type() == vt.type() && u.data && vt.data && w.data ); |
| 1599 | CV_Assert( u.cols >= nm && vt.rows >= nm && |
| 1600 | (w.size() == Size(nm, 1) || w.size() == Size(1, nm) || w.size() == Size(vt.rows, u.cols)) ); |
| 1601 | CV_Assert( rhs.data == 0 || (rhs.type() == type && rhs.rows == m) ); |
| 1602 | |
| 1603 | _dst.create( n, nb, type ); |
| 1604 | Mat dst = _dst.getMat(); |
| 1605 | if( type == CV_32F ) |
| 1606 | SVBkSb(m, n, w.ptr<float>(), wstep, u.ptr<float>(), u.step, false, |
| 1607 | vt.ptr<float>(), vt.step, true, rhs.ptr<float>(), rhs.step, nb, |
| 1608 | dst.ptr<float>(), dst.step, buffer); |
| 1609 | else if( type == CV_64F ) |
| 1610 | SVBkSb(m, n, w.ptr<double>(), wstep, u.ptr<double>(), u.step, false, |
| 1611 | vt.ptr<double>(), vt.step, true, rhs.ptr<double>(), rhs.step, nb, |
| 1612 | dst.ptr<double>(), dst.step, buffer); |
| 1613 | else |
| 1614 | CV_Error( CV_StsUnsupportedFormat, "" ); |
| 1615 | } |
| 1616 | |
| 1617 | |
| 1618 | SVD& SVD::operator ()(InputArray a, int flags) |