Return the diagonal matrix of singular values

@return S
337315
public double[][] getS() {
    double[][] S = new double[n][n];
    for(int i = 0; i < n; i++) {
      S[i][i] = this.s[i];
    }
    return S;
  }
779994
public int rank() {
        if (!full) {
            throw new IllegalStateException("This is not a FULL singular value decomposition.");
        }

        int r = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] > tol) {
                r++;
            }
        }
        return r;
    }
107558
@Override
	public DoubleMatrix1D getMatrixScalingFactorsSymm(DoubleMatrix2D A) {
		int n = A.rows();
		final double log10_b = Math.log10(base);
		
		final int[] x = new int[n];
		final double[] cHolder = new double[1];
		final double[] tHolder = new double[1];
		final int[] currentColumnIndexHolder = new int[] { -1 };
		IntIntDoubleFunction myFunct = new IntIntDoubleFunction() {
			@Override
			public double apply(int i, int j, double pij) {
				int currentColumnIndex = currentColumnIndexHolder[0];
				// we take into account only the lower left subdiagonal part of Q (that is symmetric)
				if(i == currentColumnIndex){
				  //diagonal element
					//log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij);
					tHolder[0] = tHolder[0] - 0.5 * (Math.log10(Math.abs(pij))/log10_b + 0.5);//log(b, x) = log(k, x) / log(k, b)
					cHolder[0] = cHolder[0] + 1;
				}else if (i > currentColumnIndex) {
				  //sub-diagonal elements
					//log.debug("i:" + i + ", j:" + currentColumnIndex + ": " + pij);
					tHolder[0] = tHolder[0] - 2 * (Math.log10(Math.abs(pij))/log10_b + 0.5) -2*x[i];//log(b, x) = log(k, x) / log(k, b)
					cHolder[0] = cHolder[0] + 2;//- 2*x[i]
				}
				return pij;
			}
		};
		
		//view A column by column
		for (int currentColumnIndex = n - 1; currentColumnIndex >= 0; currentColumnIndex--) {
			//log.debug("currentColumnIndex:" + currentColumnIndex);
			cHolder[0] = 0;//reset
			tHolder[0] = 0;//reset
			currentColumnIndexHolder[0] = currentColumnIndex;
			DoubleMatrix2D P = A.viewPart(0, currentColumnIndex, n, 1);
			P.forEachNonZero(myFunct);
			if(cHolder[0] > 0){
				x[currentColumnIndex] = (int)Math.round(tHolder[0] / cHolder[0]);
			}
		}
		
		//log.debug("x: " + ArrayUtils.toString(x));
		
		DoubleMatrix1D u = new DenseDoubleMatrix1D(n);
		for (int k = 0; k < n; k++) {
			u.setQuick(k, Math.pow(base, x[k]));
		}
		return u;
	}
1092698
public function getL()
    {
        $L = [];
        for ($i = 0; $i < $this->m; ++$i) {
            for ($j = 0; $j < $this->n; ++$j) {
                if ($i > $j) {
                    $L[$i][$j] = $this->LU[$i][$j];
                } elseif ($i == $j) {
                    $L[$i][$j] = 1.0;
                } else {
                    $L[$i][$j] = 0.0;
                }
            }
        }
        return new Matrix($L);
    }
409352
public DMatrixRMaj getQ() {
        DMatrixRMaj Q = CommonOps_DDRM.identity(QR.numRows);
        DMatrixRMaj Q_k = new DMatrixRMaj(QR.numRows,QR.numRows);
        DMatrixRMaj u = new DMatrixRMaj(QR.numRows,1);

        DMatrixRMaj temp = new DMatrixRMaj(1,1);

        int N = Math.min(QR.numCols,QR.numRows);

        // compute Q by first extracting the householder vectors from the columns of QR and then applying it to Q
        for( int j = N-1; j>= 0; j-- ) {
            CommonOps_DDRM.extract(QR,j, QR.numRows,j,j+1,u,j,0);
            u.set(j,1.0);

            // A = (I - &gamma;*u*u<sup>T</sup>)*A<br>
            CommonOps_DDRM.setIdentity(Q_k);
            CommonOps_DDRM.multAddTransB(-gammas[j],u,u,Q_k);
            CommonOps_DDRM.mult(Q_k,Q,temp);
            Q.set(temp);
        }

        return Q;
    }
1146624
public IMatrix transpose() {
        IMatrix result = new IMatrix(rows, columns);
        transpose(result);
        return result;
    }
1163175
function() {
            	if (!this.isSquare() || this.isSingular()) { return null; }
            	var n = this.elements.length, i = n, j;
            	var M = this.augment(Matrix$b.I(n)).toRightTriangular();
            	var np = M.elements[0].length, p, els, divisor;
            	var inverse_elements = [], new_element;
            	// Matrix is non-singular so there will be no zeros on the diagonal
            	// Cycle through rows from last to first
            	while (i--) {
            	    // First, normalise diagonal elements to 1
            	    els = [];
            	    inverse_elements[i] = [];
            	    divisor = M.elements[i][i];
            	    for (p = 0; p < np; p++) {
                    new_element = M.elements[i][p] / divisor;
            		els.push(new_element);
            		// Shuffle off the current row of the right hand side into the results
            		// array as it will not be modified by later runs through this loop
            		if (p >= n) { inverse_elements[i].push(new_element); }
            	    }
            	    M.elements[i] = els;
            	    // Then, subtract this row from those above it to
            	    // give the identity matrix on the left hand side
            	    j = i;
            	    while (j--) {
            		els = [];
            		for (p = 0; p < np; p++) {
            		    els.push(M.elements[j][p] - M.elements[i][p] * M.elements[j][i]);
            		}
            		M.elements[j] = els;
            	    }
            	}
            	return Matrix$b.create(inverse_elements);
                }
343852
public Matrix getL () {
		Matrix X = new Matrix(m,n);
		double[][] L = X.getArray();
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (i > j) {
					L[i][j] = LU[i][j];
				} else if (i == j) {
					L[i][j] = 1.0;
				} else {
					L[i][j] = 0.0;
				}
			}
		}
		return X;
	}
1152201
public Matrix transpose()
    {
        double tv[][] = new double[nCols][nRows];  // transposed values

        // Set the values of the transpose.
        for (int r = 0; r < nRows; ++r) {
            for (int c = 0; c < nCols; ++c) {
                tv[c][r] = values[r][c];
            }
        }

        return new Matrix(tv);
    }
19317
public Matrix getH () {
		Matrix X = new Matrix(m,n);
		double[][] H = X.getArray();
		for (int i = 0; i < m; i++) {
			for (int j = 0; j < n; j++) {
				if (i >= j) {
					H[i][j] = QR[i][j];
				} else {
					H[i][j] = 0.0;
				}
			}
		}
		return X;
	}
1151953
public function diagonalAsVector() : Vector
    {
        if (!$this->isSquare()) {
            throw new RuntimeException('Cannot trace diagonal of a'
                . ' non square matrix.');
        }

        $b = [];

        for ($i = 0; $i < $this->m; $i++) {
            $b[] = $this->a[$i][$i];
        }

        return Vector::quick($b);
    }
616373
public Matrix getR () {
		Matrix X = new Matrix(n,n);
		double[][] R = X.getArray();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i < j) {
					R[i][j] = QR[i][j];
				} else if (i == j) {
					R[i][j] = Rdiag[i];
				} else {
					R[i][j] = 0.0;
				}
			}
		}
		return X;
	}
320578
public static int rank( DMatrixRMaj A  ) {
        SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,true,true);

        if( svd.inputModified() ) {
            A = A.copy();
        }
        if( !svd.decompose(A)) {
            throw new RuntimeException("SVD Failed!");
        }

        int N = svd.numberOfSingularValues();
        double sv[] = svd.getSingularValues();

        double threshold = singularThreshold(sv,N);
        int count = 0;
        for (int i = 0; i < sv.length; i++) {
            if( sv[i] >= threshold ) {
                count++;
            }
        }
        return count;
    }
1054031
@Nonnull
  public Matrix getU ()
  {
    final Matrix aNewMatrix = new Matrix (m_nCols, m_nCols);
    final double [] [] aNewArray = aNewMatrix.internalGetArray ();
    for (int nRow = 0; nRow < m_nCols; nRow++)
    {
      final double [] aSrcRow = m_aLU[nRow];
      final double [] aDstRow = aNewArray[nRow];
      for (int nCol = 0; nCol < m_nCols; nCol++)
        if (nRow <= nCol)
          aDstRow[nCol] = aSrcRow[nCol];
        else
          aDstRow[nCol] = 0.0;
    }
    return aNewMatrix;
  }
516223
public static FloatMatrix SVDValues(ComplexFloatMatrix A) {
        int m = A.rows;
        int n = A.columns;
        FloatMatrix S = new FloatMatrix(min(m, n));
        float[] rwork = new float[5*min(m,n)];

        int info = NativeBlas.cgesvd('N', 'N', m, n, A.dup().data, 0, m, S.data, 0, null, 0, 1, null, 0, min(m,n), rwork, 0);

        if (info > 0) {
          throw new LapackConvergenceException("GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
        }

        return S;
    }
622682
private void makeSingularPositive() {
        numSingular = qralg.getNumberOfSingularValues();
        singularValues = qralg.getSingularValues();

        for( int i = 0; i < numSingular; i++ ) {
            double val = singularValues[i];

            if( val < 0 ) {
                singularValues[i] = -val;

                if( computeU ) {
                    // compute the results of multiplying it by an element of -1 at this location in
                    // a diagonal matrix.
                    int start = i* Ut.numCols;
                    int stop = start+ Ut.numCols;

                    for( int j = start; j < stop; j++ ) {
                        Ut.data[j] = -Ut.data[j];
                    }
                }
            }
        }
    }
929254
public static FloatMatrix SVDValues(FloatMatrix A) {
        int m = A.rows;
        int n = A.columns;
        FloatMatrix S = new FloatMatrix(min(m, n));

        int info = NativeBlas.sgesvd('N', 'N', m, n, A.dup().data, 0, m, S.data, 0, null, 0, 1, null, 0, 1);

        if (info > 0) {
          throw new LapackConvergenceException("GESVD", info + " superdiagonals of an intermediate bidiagonal form failed to converge.");
        }

        return S;
    }