Returns class cached DoubleMatrix with decompose already called.
@param n
@return
341051
protected DoubleMatrix getMatrix(int n)
    {
        Map<Integer, DoubleMatrix> degreeMap = matrixCache.get(this.getClass());
        if (degreeMap == null)
        {
            degreeMap = new HashMap<>();
            matrixCache.put(this.getClass(), degreeMap);
        }
        DoubleMatrix m = degreeMap.get(n);
        if (m == null)
        {
            m = createMatrix(n);
            m.decompose();
            degreeMap.put(n, m);
        }
        return m;
    }
416384
public static DenseMatrix matrix(int nrows, int ncols) {
        if (nlmatrixZeros != null) {
            try {
                return (DenseMatrix) nlmatrixZeros.newInstance(nrows, ncols);
            } catch (Exception e) {
                logger.error("Failed to call NLMatrix(int, int): {}", e);
            }
        }

        return new JMatrix(nrows, ncols);
    }
496746
private Matrix<Double> generateRandomMatrix(final int nRows, final int nColumns) {
    final List<List<Double>> rows = new ArrayList<>(nRows);
    final Random random = new Random();
    for (int i = 0; i < nRows; i++) {
      final List<Double> row = new ArrayList<>(nColumns);
      for (int j = 0; j < nColumns; j++) {
        row.add(random.nextDouble());
      }
      rows.add(row);
    }
    return new RowMatrix(rows);
  }
534020
public static Matrix3D identity(int N) {
        Matrix3D I = new Matrix3D(N, N, N);
        for (int i = 0; i < N; i++)
            I.data[i][i][i] = 1;
        return I;
    }
615737
public static DoubleMatrix copy(DoubleMatrix x, DoubleMatrix y) {
		//NativeBlas.dcopy(x.length, x.data, 0, 1, y.data, 0, 1);
		JavaBlas.rcopy(x.length, x.data, 0, 1, y.data, 0, 1);
		return y;
	}
1350799
public Matrix getS () {
		Matrix X = new Matrix(n,n);
		double[][] S = X.getArray();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				S[i][j] = 0.0;
			}
			S[i][i] = this.s[i];
		}
		return X;
	}
989132
public static final DoubleMatrix2D diagonalMatrixMult(final DoubleMatrix1D diagonalU, DoubleMatrix2D A, final DoubleMatrix1D diagonalV){
		int r = A.rows();
		int c = A.columns();
		final DoubleMatrix2D ret;
		if (A instanceof SparseDoubleMatrix2D) {
			ret = DoubleFactory2D.sparse.make(r, c);
			A.forEachNonZero(new IntIntDoubleFunction() {
				@Override
				public double apply(int i, int j, double aij) {
					ret.setQuick(i, j, aij * diagonalU.getQuick(i) * diagonalV.getQuick(j));
					return aij;
				}
			});
		} else {
			ret = DoubleFactory2D.dense.make(r, c);
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					ret.setQuick(i, j, A.getQuick(i, j) * diagonalU.getQuick(i)	* diagonalV.getQuick(j));
				}
			}
		}

		return ret;
	}
208972
@Override
    public Matrix[] decompose() {

        Matrix[] lup = super.decompose();
        Matrix lu = lup[0];
        Matrix p = lup[1];

        Matrix l = matrix.blankOfShape(lu.rows(), lu.columns());

        for (int i = 0; i < l.rows(); i++) {
            for (int j = 0; j <= i; j++) {
                if (i > j) {
                    l.set(i, j, lu.get(i, j));
                } else {
                    l.set(i, j, 1.0);
                }
            }
        }

        Matrix u = matrix.blankOfShape(lu.columns(), lu.columns());

        for (int i = 0; i < u.rows(); i++) {
            for (int j = i; j < u.columns(); j++) {
                u.set(i, j, lu.get(i, j));
            }
        }

        return new Matrix[] { l, u, p };
    }
1185311
@Nonnull
  @ReturnsMutableCopy
  public Matrix getL ()
  {
    final Matrix aNewMatrix = new Matrix (m_nRows, m_nCols);
    final double [] [] aNewArray = aNewMatrix.internalGetArray ();
    for (int nRow = 0; nRow < m_nRows; 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
          if (nRow == nCol)
            aDstRow[nCol] = 1.0;
          else
            aDstRow[nCol] = 0.0;
    }
    return aNewMatrix;
  }
121893
public ByteBuffer getAsMatrix4f(ByteBuffer dest) {
        MemUtil.INSTANCE.putMatrix4f(this, dest.position(), dest);
        return dest;
    }
1195892
public static AbstractMatrix getInstance(int rows, int cols, Class<?> cls)
    {
        return new AbstractMatrix(rows, Array.newInstance(cls, rows*cols));
    }
1220772
public static synchronized Cache
getDefaultCache(int dclass) {
	DClass.check(dclass);
	Cache c = (Cache) defaultCaches.get(Mnemonic.toInteger(dclass));
	if (c == null) {
		c = new Cache(dclass);
		defaultCaches.put(Mnemonic.toInteger(dclass), c);
	}
	return c;
}
777179
@Override
    public Matrix[] decompose() {

        Matrix[] qrr = super.decompose();
        Matrix qr = qrr[0];
        Matrix r = qrr[1];

        Matrix q = qr.blank();

        for (int k = q.columns() - 1; k >= 0; k--) {

            q.set(k, k, 1.0);

            for (int j = k; j < q.columns(); j++) {

                if (Math.abs(qr.get(k, k)) > Matrices.EPS) {

                    double acc = 0.0;

                    for (int i = k; i < q.rows(); i++) {
                        acc += qr.get(i, k) * q.get(i, j);
                    }

                    acc = -acc / qr.get(k, k);

                    for (int i = k; i < q.rows(); i++) {
                        q.updateAt(i, j, Matrices.asPlusFunction(acc * qr.get(i, k)));
                    }
                }
            }
        }

        for (int i = 0; i < r.rows(); i++) {
            for (int j = i + 1; j < r.columns(); j++) {
                r.set(i, j, qr.get(i, j));
            }
        }

        return new Matrix[] { q, r };
    }
516966
@Override
    public boolean decompose( ZMatrixRMaj A ) {
        init(A);

        for( int k = 0; k < N-1; k++ ) {
            similarTransform(k);
        }

        return true;
    }
1090781
public static long get1D(DMatrixRMaj A , int n ) {

        long before = System.currentTimeMillis();

        double total = 0;

        for( int iter = 0; iter < n; iter++ ) {

            int index = 0;
            for( int i = 0; i < A.numRows; i++ ) {
                int end = index+A.numCols;
                while( index != end ) {
                    total += A.get(index++);
                }
            }
        }

        long after = System.currentTimeMillis();

        // print to ensure that ensure that an overly smart compiler does not optimize out
        // the whole function and to show that both produce the same results.
        System.out.println(total);

        return after-before;
    }
627770
public static DoubleMatrix getInstance(int rows, double... values)
    {
        if (rows < 1)
        {
            throw new IllegalArgumentException("rows");
        }
        if (values.length % rows != 0)
        {
            throw new IllegalArgumentException("not full rows");
        }
        return new DoubleMatrix(rows, Arrays.copyOf(values, values.length));
    }
1296521
public static byte [] scalseMult_base(byte [] n) {
            if (!(n.length==scalarLength))
                return null;

            byte [] q = new byte [scalarLength];

            crypto_scalarmult_base(q, n);

            return q;
        }