Example #1
0
        private bool setup(DMatrixRMaj orig)
        {
            transposed = orig.numCols > orig.numRows;

            // flag what should be computed and what should not be computed
            if (transposed)
            {
                computeU  = prefComputeV;
                computeV  = prefComputeU;
                _numRowsT = orig.numCols;
                _numColsT = orig.numRows;
            }
            else
            {
                computeU  = prefComputeU;
                computeV  = prefComputeV;
                _numRowsT = orig.numRows;
                _numColsT = orig.numCols;
            }

            _numRows = orig.numRows;
            _numCols = orig.numCols;

            if (_numRows == 0 || _numCols == 0)
            {
                return(false);
            }

            if (diag == null || diag.Length < _numColsT)
            {
                diag = new double[_numColsT];
                off  = new double[_numColsT - 1];
            }

            // if it is a tall matrix and U is not needed then there is faster decomposition algorithm
            if (_canUseTallBidiagonal && _numRows > _numCols * 2 && !computeU)
            {
                if (bidiag == null || !(bidiag is BidiagonalDecompositionTall_DDRM))
                {
                    bidiag = new BidiagonalDecompositionTall_DDRM();
                }
            }
            else if (bidiag == null || !(bidiag is BidiagonalDecompositionRow_DDRM))
            {
                bidiag = new BidiagonalDecompositionRow_DDRM();
            }

            return(true);
        }