Compute the singular values of a complex matrix.

@param A ComplexFloatMatrix of dimension m * n
@return A real-valued (!) min(m, n) vector of singular values.
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;
    }
590725
public Matrix solve (Matrix B) {
      if (B.getRowDimension() != m) {
         throw new IllegalArgumentException("Matrix row dimensions must agree.");
      }
      if (!this.isNonsingular()) {
         throw new RuntimeException("Matrix is singular.");
      }

      // Copy right hand side with pivoting
      int nx = B.getColumnDimension();
      Matrix Xmat = B.getMatrix(piv,0,nx-1);
      double[][] X = Xmat.getArray();

      // Solve L*Y = B(piv,:)
      for (int k = 0; k < n; k++) {
         for (int i = k+1; i < n; i++) {
            for (int j = 0; j < nx; j++) {
               X[i][j] -= X[k][j]*LU[i][k];
            }
         }
      }
      // Solve U*X = Y;
      for (int k = n-1; k >= 0; k--) {
         for (int j = 0; j < nx; j++) {
            X[k][j] /= LU[k][k];
         }
         for (int i = 0; i < k; i++) {
            for (int j = 0; j < nx; j++) {
               X[i][j] -= X[k][j]*LU[i][k];
            }
         }
      }
      return Xmat;
   }
932089
@Override
    public Complex_F64 computeDeterminant() {
        if( m != n )
            throw new IllegalArgumentException("Must be a square matrix.");

        double realRet = pivsign;
        double realImg = 0;

        int total = m*stride;
        for( int i = 0; i < total; i += stride + 2 ) {
            double real = dataLU[i];
            double imaginary = dataLU[i+1];

            double r = realRet*real - realImg*imaginary;
            double t = realRet*imaginary + realImg*real;

            realRet = r;
            realImg = t;
        }

        det.set(realRet,realImg);
        return det;
    }
417852
public static DMatrixRMaj nullspaceQR( DMatrixRMaj A , int totalSingular ) {
        SolveNullSpaceQR_DDRM solver = new SolveNullSpaceQR_DDRM();

        DMatrixRMaj nullspace = new DMatrixRMaj(1,1);

        if( !solver.process(A,totalSingular,nullspace))
            throw new RuntimeException("Solver failed. try SVD based method instead?");

        return nullspace;
    }
120302
public static double elementSum( DMatrixSparseCSC A ) {
        if( A.nz_length == 0)
            return 0;

        double sum = 0;
        for(int i = 0; i < A.nz_length; i++ ) {
            sum += A.nz_values[i];
        }

        return sum;
    }
1103701
public static double fastNormF( DMatrixD1 a ) {
        double total = 0;

        int size = a.getNumElements();

        for( int i = 0; i < size; i++ ) {
            double val = a.get(i);
            total += val*val;
        }

        return Math.sqrt(total);
    }
428758
private void makeSingularPositive() {
        numSingular = qralg.getNumberOfSingularValues();
        singularValues = qralg.getSingularValues();

        for( int i = 0; i < numSingular; i++ ) {
            double val = qralg.getSingularValue(i);

            if( val < 0 ) {
                singularValues[i] = 0.0 - 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.set(j, 0.0 - Ut.get(j));
                    }
                }
            } else {
                singularValues[i] = val;
            }
        }
    }
231345
public static DMatrixRMaj checkZerosLT(DMatrixRMaj A , int numRows , int numCols) {
        if( A == null ) {
            return new DMatrixRMaj(numRows,numCols);
        }  else if( numRows != A.numRows || numCols != A.numCols ) {
            A.reshape(numRows,numCols);
            A.zero();
        } else {
            for( int i = 0; i < A.numRows; i++ ) {
                int index = i*A.numCols;
                int end = index + Math.min(i,A.numCols);;
                while( index < end ) {
                    A.data[index++] = 0;
                }
            }
        }
        return A;
    }
184235
public static double elementMin( DMatrix4 a ) {
        double min = a.a1;
        if( a.a2 < min ) min = a.a2;
        if( a.a3 < min ) min = a.a3;
        if( a.a4 < min ) min = a.a4;

        return min;
    }
599156
public static SingularValueDecomposition getFactorization(Algorithm alg) {
        switch (alg)  {
            case MATLAB: return new SingularValueDecompositionMatlab();
            case OCTAVE: return new SingularValueDecompositionOctave();
            case SVDLIBC: return new SingularValueDecompositionLibC();
            case ANY: return getFastestAvailableFactorization();
            default: throw new UnsupportedOperationException(
                "Cannot find a valid SVD implementation");
        }
    }
654660
public static ComplexDoubleMatrix geru(ComplexDouble alpha, ComplexDoubleMatrix x,
			ComplexDoubleMatrix y, ComplexDoubleMatrix a) {
		NativeBlas.zgeru(a.rows, a.columns, alpha, x.data, 0, 1, y.data, 0, 1, a.data,
				0, a.rows);
		return a;
	}
66810
def apply_M(self, ax, ay):
        
        jac = numpy.array(
            [[self.dx.dot(ax), self.dy.dot(ax)], [self.dx.dot(ay), self.dy.dot(ay)]]
        )

        # jacs and J are of shape (2, 2, k). M must be of the same shape and
        # contain the result of the k 2x2 dot products. Perhaps there's a
        # dot() for this.
        M = numpy.einsum("ijl,jkl->ikl", jac, self.J)
        # M = numpy.array([
        #     [
        #         jac[0][0]*self.J[0][0] + jac[0][1]*self.J[1][0],
        #         jac[0][0]*self.J[0][1] + jac[0][1]*self.J[1][1],
        #     ],
        #     [
        #         jac[1][0]*self.J[0][0] + jac[1][1]*self.J[1][0],
        #         jac[1][0]*self.J[0][1] + jac[1][1]*self.J[1][1],
        #     ],
        #     ])

        # One could use
        #
        #     M = numpy.moveaxis(M, -1, 0)
        #     _, sigma, _ = numpy.linalg.svd(M)
        #
        # but computing the singular values explicitly via
        # <https://scicomp.stackexchange.com/a/14103/3980> is faster and more
        # explicit.
        a = (M[0, 0] + M[1, 1]) / 2
        b = (M[0, 0] - M[1, 1]) / 2
        c = (M[1, 0] + M[0, 1]) / 2
        d = (M[1, 0] - M[0, 1]) / 2

        return a, b, c, d
1149210
public static ZMatrixRMaj[] columnsToVector(ZMatrixRMaj A, ZMatrixRMaj[] v)
    {
        ZMatrixRMaj[]ret;
        if( v == null || v.length < A.numCols ) {
            ret = new ZMatrixRMaj[ A.numCols ];
        } else {
            ret = v;
        }

        for( int i = 0; i < ret.length; i++ ) {
            if( ret[i] == null ) {
                ret[i] = new ZMatrixRMaj(A.numRows,1);
            } else {
                ret[i].reshape(A.numRows,1);
            }

            ZMatrixRMaj u = ret[i];

            int indexU = 0;
            for( int j = 0; j < A.numRows; j++ ) {
                int indexA = A.getIndex(j,i);
                u.data[indexU++] = A.data[indexA++];
                u.data[indexU++] = A.data[indexA];
            }
        }

        return ret;
    }
853398
public static double inducedP2( DMatrixRMaj A ) {
        SingularValueDecomposition_F64<DMatrixRMaj> svd = DecompositionFactory_DDRM.svd(A.numRows,A.numCols,false,false,true);

        if( !svd.decompose(A) )
            throw new RuntimeException("Decomposition failed");

        double[] singularValues = svd.getSingularValues();

        // the largest singular value is the induced p2 norm
        return UtilEjml.max(singularValues,0,singularValues.length);
    }
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;
	}
304945
public static double elementMin( DMatrixSparseCSC A ) {
        if( A.nz_length == 0)
            return 0;

        // if every element is assigned a value then the first element can be a minimum.
        // Otherwise zero needs to be considered
        double min = A.isFull() ? A.nz_values[0] : 0;
        for(int i = 0; i < A.nz_length; i++ ) {
            double val = A.nz_values[i];
            if( val < min ) {
                min = val;
            }
        }

        return min;
    }
662235
private SimpleMatrix computeHZero( DMatrixRMaj F , Point3D_F64 e2 ,
									   SimpleMatrix H ) {

		Vector3D_F64 v = new Vector3D_F64(.1,0.5,.2);

		// need to make sure M is not singular for this technique to work
		SimpleMatrix P = SimpleMatrix.wrap(MultiViewOps.fundamentalToProjective(F, e2, v, 1));

		SimpleMatrix M = P.extractMatrix(0, 3, 0, 3);

		return H.mult(M);
	}