Most typical factory, for BigInteger arrays.

@param inMatrix given in BigIntegers, where the first column is the constant
and all the other columns are the variables
@return instance
490086
public static EasyLinearEquation create(BigInteger[][] inMatrix)
    {
        EasyLinearEquation ret = null;
        final int width = inMatrix[0].length;
        for (BigInteger[] row : inMatrix)
        {
            if (width != row.length)
            {
                throw new SecretShareException("All rows must be " +
                                               width + " wide");
            }
        }
        List<Row> rows = new ArrayList<Row>();
        for (BigInteger[] row : inMatrix)
        {
            Row add = Row.create(row);
            rows.add(add);
        }
        ret = new EasyLinearEquation(rows);
        return ret;
    }
445042
public static DoubleMatrix getInstance(int rows, int cols, ItemSupplier s)
    {
        DoubleMatrix m = new DoubleMatrix(rows, cols);
        ItemConsumer c = m.consumer;
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                c.set(i, j, s.get(i, j));
            }
        }
        return m;
    }
937483
private Matrix getThisSideMatrix(Matrix B)
    {
        if(this.canBeMutated())
            return this.clone();
        else//so far, only other option in JSAT is a dense matrix
        {
            DenseMatrix dm = new DenseMatrix(rows(), cols());
            dm.mutableAdd(this);
            return dm;
        }
    }
45219
public static double[][] getMatrix(final double[][] m1, final int r0, final int r1, final int[] c) {
    assert r0 <= r1 : ERR_INVALID_RANGE;
    assert r1 <= m1.length : ERR_MATRIX_DIMENSIONS;
    final int rowdim = r1 - r0, coldim = c.length;
    final double[][] X = new double[rowdim][coldim];
    for(int i = r0; i < r1; i++) {
      final double[] row = m1[i];
      final double[] Xi = X[i - r0];
      for(int j = 0; j < coldim; j++) {
        Xi[j] = row[c[j]];
      }
    }
    return X;
  }
266800
public static DMatrix4x4 convert(DMatrixRMaj input , DMatrix4x4 output ) {
        if( output == null)
            output = new DMatrix4x4();

        if( input.getNumRows() != output.getNumRows() )
            throw new IllegalArgumentException("Number of rows do not match");
        if( input.getNumCols() != output.getNumCols() )
            throw new IllegalArgumentException("Number of columns do not match");

        output.a11 = input.data[0];
        output.a12 = input.data[1];
        output.a13 = input.data[2];
        output.a14 = input.data[3];
        output.a21 = input.data[4];
        output.a22 = input.data[5];
        output.a23 = input.data[6];
        output.a24 = input.data[7];
        output.a31 = input.data[8];
        output.a32 = input.data[9];
        output.a33 = input.data[10];
        output.a34 = input.data[11];
        output.a41 = input.data[12];
        output.a42 = input.data[13];
        output.a43 = input.data[14];
        output.a44 = input.data[15];

        return output;
    }
239828
@Override
    protected StatisticsMatrix createMatrix(int numRows, int numCols, MatrixType type) {
        return new StatisticsMatrix(numRows,numCols);
    }
1230297
public static DoubleMatrix centerColumns(DoubleMatrix x) {
                DoubleMatrix temp = new DoubleMatrix(x.rows);
		for (int c = 0; c < x.columns; c++)
			x.putColumn(c, center(x.getColumn(c, temp)));
		return x;
	}
1011640
private static boolean[] createInitialR(CompRowMatrix A) {
            boolean[] R = new boolean[A.numRows()];

            int[] rowptr = A.getRowPointers();
            int[] colind = A.getColumnIndices();
            double[] data = A.getData();

            for (int i = 0; i < A.numRows(); ++i) {
                boolean hasOffDiagonal = false;

                for (int j = rowptr[i]; j < rowptr[i + 1]; ++j)
                    if (colind[j] != i && data[j] != 0) {
                        hasOffDiagonal = true;
                        break;
                    }

                R[i] = hasOffDiagonal;
            }

            return R;
        }
494122
public static PermutationMatrix getInstance(int n)
    {
        PermutationMatrix pm = map.get(n);
        if (pm == null)
        {
            pm = new PermutationMatrix(n);
            map.put(n, pm);
        }
        return pm;
    }
821072
public static String[][] createMatrix(final String[] data) {
        int maxNewLines = 0;
        for (final String col : data) {
            maxNewLines = Math.max(maxNewLines, Util.numNewLines(col));
        }
        final String[][] matrix = new String[maxNewLines + 1][data.length];
        for (int col = 0; col < data.length; col++) {
            final String[] exploded = Util.explode(data[col]);
            for (int row = 0; row < maxNewLines + 1; row++) {
                if (exploded.length > row) {
                    matrix[row][col] = exploded[row];
                } else {
                    matrix[row][col] = "";
                }
            }
        }

        return matrix;

    }
353571
public static DoubleMatrix permutationDoubleMatrixFromPivotIndices(int size, int[] ipiv) {
        int n = ipiv.length;
        //System.out.printf("size = %d n = %d\n", size, n);
        int indices[] = new int[size];
        for (int i = 0; i < size; i++)
            indices[i] = i;

        //for (int i = 0; i < n; i++)
        //    System.out.printf("ipiv[%d] = %d\n", i, ipiv[i]);

        for (int i = 0; i < n; i++) {
            int j = ipiv[i] - 1;
            int t = indices[i];
            indices[i] = indices[j];
            indices[j] = t;
        }
        DoubleMatrix result = new DoubleMatrix(size, size);
        for (int i = 0; i < size; i++)
            result.put(indices[i], i, 1.0);
        return result;
    }
1285072
@Override
	public DoubleMatrix1D[] getMatrixScalingFactors(DoubleMatrix2D A){
		DoubleFactory1D F1 = DoubleFactory1D.dense;
		Algebra ALG = Algebra.DEFAULT;
		int r = A.rows();
		int c = A.columns();
		DoubleMatrix1D D1 = F1.make(r, 1);
		DoubleMatrix1D D2 = F1.make(c, 1);
		DoubleMatrix2D AK = A.copy();
		DoubleMatrix1D DR = F1.make(r, 1);
		DoubleMatrix1D DC = F1.make(c, 1);
		DoubleMatrix1D DRInv = F1.make(r);
		DoubleMatrix1D DCInv = F1.make(c);
		log.debug("eps  : " + eps);
		int maxIteration = 50;
		for(int k=0; k<=maxIteration; k++){
			double normR = -Double.MAX_VALUE;
			double normC = -Double.MAX_VALUE;
			for(int i=0; i<r; i++){
				double dri = ALG.normInfinity(AK.viewRow(i));
				DR.setQuick(i, Math.sqrt(dri));
				DRInv.setQuick(i, 1./Math.sqrt(dri));
				normR = Math.max(normR, Math.abs(1-dri));
			}
			for(int j=0; j<c; j++){
				double dci = ALG.normInfinity(AK.viewColumn(j));
				DC.setQuick(j, Math.sqrt(dci));
				DCInv.setQuick(j, 1./Math.sqrt(dci));
				normC = Math.max(normC, Math.abs(1-dci));
			}
			
			log.debug("normR: " + normR);
			log.debug("normC: " + normC);
			if(normR < eps && normC < eps){
				break;
			}
			
			//D1 = ALG.mult(D1, DRInv);
			for(int i=0; i<r; i++){
				double prevD1I = D1.getQuick(i);
				double newD1I = prevD1I * DRInv.getQuick(i);
				D1.setQuick(i, newD1I);
			}
			//D2 = ALG.mult(D2, DCInv);
			for(int j=0; j<c; j++){
				double prevD2J = D2.getQuick(j);
				double newD2J = prevD2J * DCInv.getQuick(j);
				D2.setQuick(j, newD2J);
			}
			//log.debug("D1: " + ArrayUtils.toString(D1.toArray()));
			//log.debug("D2: " + ArrayUtils.toString(D2.toArray()));
			
			if(k==maxIteration){
				log.warn("max iteration reached");
			}
			
			//AK = ALG.mult(DRInv, ALG.mult(AK, DCInv));
			AK = ColtUtils.diagonalMatrixMult(DRInv, AK, DCInv);
		}
		
		return new DoubleMatrix1D[]{D1, D2};
	}
1371304
public static SparseMatrix random(int[] dim) {
		Random r = new Random();
		SparseMatrix matrix = new SparseMatrix(dim);
		for(int i=0;i<dim[0];i++)
			for(int j=0;j<dim[1];j++)
			{
				int []indices={i,j};
				matrix.set(indices, r.nextFloat());
			}
		return matrix;
	}
1054901
public static FloatMatrix centerColumns(FloatMatrix x) {
                FloatMatrix temp = new FloatMatrix(x.rows);
		for (int c = 0; c < x.columns; c++)
			x.putColumn(c, center(x.getColumn(c, temp)));
		return x;
	}
367170
public static Basic2DMatrix from1DArray(int rows, int columns, double[] array) {
        double[][] array2D = new double[rows][columns];

        for (int i = 0; i < rows; i++) {
            System.arraycopy(array, i * columns, array2D[i], 0, columns);
        }

        return new Basic2DMatrix(array2D);
    }
1006887
public int dot(int[][] matrix, int col) {
        int ret = 0;
        for (int c = 0; c < used && indices[c] < matrix.length; c++) {
            if (indices[c] > Integer.MAX_VALUE) {
                break;
            }
            ret += values[c] * matrix[SafeCast.safeLongToInt(indices[c])][col];
        }
        return ret;
    }
464262
public static DenseDoubleMatrix2D inverse(final double[][] matrix) {
		double epsilon = UJMPSettings.getInstance().getTolerance();
		int rows = matrix.length;
		int cols = matrix[0].length;
		double[][] s = new double[cols][cols];
		for (int c = 0; c < cols; c++) {
			s[c][c] = 1.0;
		}
		final double[][] t = new double[rows][rows];
		for (int r = 0; r < rows; r++) {
			t[r][r] = 1.0;
		}
		int maxDiag = Math.min(rows, cols);

		int diag = 0;
		for (; diag < maxDiag; diag++) {

			// get the largest value for the pivot
			swapPivot(matrix, diag, s, t);

			if (matrix[diag][diag] == 0.0) {
				break;
			}

			// divide through to make pivot identity
			double divisor = matrix[diag][diag];
			if (Math.abs(divisor) < epsilon) {
				matrix[diag][diag] = 0.0;
				break;
			}

			divideRowBy(matrix, diag, diag, divisor);
			divideRowBy(t, diag, 0, divisor);
			matrix[diag][diag] = 1.0;

			// remove values down remaining rows
			for (int row = diag + 1; row < rows; row++) {
				double factor = matrix[row][diag];
				if (factor != 0.0) {
					addRowTimes(matrix, diag, diag, row, factor);
					addRowTimes(t, diag, 0, row, factor);
					matrix[row][diag] = 0.0;
				}
			}

			// remove values across remaining cols - some optimization could
			// be done here because the changes to the original matrix at this
			// point only touch the current diag column
			for (int col = diag + 1; col < cols; col++) {
				double factor = matrix[diag][col];
				if (factor != 0.0) {
					addColTimes(matrix, diag, diag, col, factor);
					addColTimes(s, diag, 0, col, factor);
					matrix[diag][col] = 0.0;
				}
			}
		}

		double[][] result = times(s, t, diag);
		return new ArrayDenseDoubleMatrix2D(result);
	}