/*
public Matrix calcS() { int i,j; Matrix S = new Matrix(N,N); for(i=0;
i<N; i++) for(j=0; j<N; j++) if (i==j) S.matrix[i][j] = 1d; else
S.matrix[i][j] = 0d; return S; }
499248
@Override
    public double calcJ(int i, int j) {
        double result = 0d;
        for (int l = 1; l <= N2; l++)
            result += Math.cos(l * 2 * Math.PI * (i - j) / N) * Tl * l * l;
        return result * 2d / N;
    }

    /*
     * public Matrix calcT() { int i,j,l; Matrix T = new Matrix(N,N); double Tl
     * = (2/m)*(hdash*Math.PI/(N*dx))*(hdash*Math.PI/(N*dx)); int n = (N-1)/2;
     * for(i=0; i<N; i++) for(j=0; j<N; j++) { T.matrix[i][j] = 0d; for(l=1;
     * l<=n; l++) T.matrix[i][j] += Math.cos(l*2*Math.PI*(i-j)/N)*Tl*l*l;
     * T.matrix[i][j] *= 2d/N; } return T; }
     */

    @Override
    public double calcV(int i, int j) {
        if (i == j) return potential.getValue(minx + dx * i, 0d, 0d);
        return 0d;
    }

    /*
     * public Matrix calcV() { int i,j; Matrix V = new Matrix(N,N); for(i=0;
     * i<N; i++) for(j=0; j<N; j++) V.matrix[i][j] = 0d; for(i=0; i<N; i++)
     * V.matrix[i][i] = potential.getValue(minx+dx*i, 0d, 0d); return V; }
     */

    /*
     * public Matrix getS() { return S; } public Matrix getT() { return T; }
     * public Matrix getV() { return V; }
     */

    @Override
    public double calcI(int i, int j, int k, int l) {
        return 0d;
    }
459033
public float[] matrix() {
		float[] matrix = new float[8];
		float cosX = (float) Math.cos(rotationRadians);
		float sinX = (float) Math.sin(rotationRadians);
		matrix[AX] = plainWidth * cosX;
		matrix[AY] = plainWidth * sinX;
		matrix[BX] = (-plainHeight) * sinX;
		matrix[BY] = plainHeight * cosX;
		if (rotationRadians < Math.PI / 2f) {
			matrix[CX] = matrix[BX];
			matrix[CY] = 0;
			matrix[DX] = matrix[AX];
			matrix[DY] = matrix[AY] + matrix[BY];
		} else if (rotationRadians < Math.PI) {
			matrix[CX] = matrix[AX] + matrix[BX];
			matrix[CY] = matrix[BY];
			matrix[DX] = 0;
			matrix[DY] = matrix[AY];
		} else if (rotationRadians < Math.PI * 1.5f) {
			matrix[CX] = matrix[AX];
			matrix[CY] = matrix[AY] + matrix[BY];
			matrix[DX] = matrix[BX];
			matrix[DY] = 0;
		} else {
			matrix[CX] = 0;
			matrix[CY] = matrix[AY];
			matrix[DX] = matrix[AX] + matrix[BX];
			matrix[DY] = matrix[BY];
		}
		return matrix;
	}
326065
public static int max(int[][] matrix) {
        int m = matrix[0][0];

        for (int[] x : matrix) {
            for (int y : x) {
                if (m < y) {
                    m = y;
                }
            }
        }

        return m;
    }
37046
function() {
                var rows = this.elements.length, i, cols = this.elements[0].length, j;
            	var elements = [], i = cols;
            	while (i--) {
            	    j = rows;
            	    elements[i] = [];
            	    while (j--) {
            		elements[i][j] = this.elements[j][i];
            	    }
            	}
            	return Matrix$b.create(elements);
                }
1298571
public DMatrixRMaj getR() {
        DMatrixRMaj R = new DMatrixRMaj(QR.numRows,QR.numCols);
        int N = Math.min(QR.numCols,QR.numRows);

        for( int i = 0; i < N; i++ ) {
            for( int j = i; j < QR.numCols; j++ ) {
                R.unsafe_set(i,j, QR.unsafe_get(i,j));
            }
        }

        return R;
    }
1334511
public double compute( DMatrix1Row mat ) {
        if( width != mat.numCols || width != mat.numRows ) {
            throw new RuntimeException("Unexpected matrix dimension");
        }

        // make sure everything is in the proper state before it starts
        initStructures();

//        System.arraycopy(mat.data,0,minorMatrix[0],0,mat.data.length);

        int level = 0;
        while( true ) {
            int levelWidth = width-level;
            int levelIndex = levelIndexes[level];

            if( levelIndex == levelWidth ) {
                if( level == 0 ) {
                    return levelResults[0];
                }
                int prevLevelIndex = levelIndexes[level-1]++;

                double val = mat.get((level-1)*width+levelRemoved[level-1]);
                if( prevLevelIndex % 2 == 0 ) {
                    levelResults[level-1] += val * levelResults[level];
                } else {
                    levelResults[level-1] -= val * levelResults[level];
                }

                putIntoOpen(level-1);

                levelResults[level] = 0;
                levelIndexes[level] = 0;
                level--;
            } else {
                int excluded = openRemove( levelIndex );

                levelRemoved[level] = excluded;

                if( levelWidth == minWidth ) {
                    createMinor(mat);
                    double subresult = mat.get(level*width+levelRemoved[level]);

                    subresult *= UnrolledDeterminantFromMinor_DDRM.det(tempMat);

                    if( levelIndex % 2 == 0 ) {
                        levelResults[level] += subresult;
                    } else {
                        levelResults[level] -= subresult;
                    }

                    // put it back into the list
                    putIntoOpen(level);
                    levelIndexes[level]++;
                } else {
                    level++;
                }
            }
        }
    }
1217530
private final int m() {
        int n = 0;
        int i = 0;
        for (; cons(i); ++i) {
            if (i > j)
                return n;
        }
        i++;
        while(i <= j) {
            for (; !cons(i); ++i) {
                if (i > j)
                    return n;
            }
            i++;
            n++;

            if (i > j)
                return n;
            for (; cons(i); ++i) {
                if (i > j)
                    return n;
            }
            i++;
        }
        return n;
    }
533001
@Override
	public int[][][] getScoreMatrix() {
		boolean tempStoringScoreMatrix = storingScoreMatrix;
		if (scores == null) {
			storingScoreMatrix = true;
			align();
			if (scores == null) {
				return null;
			}
		}
		int[][][] copy = scores;
		if (tempStoringScoreMatrix) {
			copy = new int[scores.length][scores[0].length][];
			for (int i = 0; i < copy.length; i++) {
				for (int j = 0; j < copy[0].length; j++) {
					copy[i][j] = Arrays.copyOf(scores[i][j], scores[i][j].length);
				}
			}
		}
		setStoringScoreMatrix(tempStoringScoreMatrix);
		return copy;
	}
1215386
function() {
      var determinant;
      determinant = this.a * this.d - this.b * this.c;
      return Matrix(this.d / determinant, -this.b / determinant, -this.c / determinant, this.a / determinant, (this.c * this.ty - this.d * this.tx) / determinant, (this.b * this.tx - this.a * this.ty) / determinant);
    }
222112
public E determinant(E[][] matrix, int r, int s, int i, int j)
    {
        E a, b, c, d;
        a = matrix[r][s];
        b = matrix[r][j];
        c = matrix[i][s];
        d = matrix[i][j];
        E ad  = multiply(a, d); // matrix[r][s], matrix[i][j]);
        E bc = multiply(b, c); // matrix[i][s], matrix[r][j]);
        E ret = subtract(ad, bc);

        return ret;
    }
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;
    }
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);
                }
858303
public Matrix times(final Matrix B)
    {
        final Matrix A = this;

        if (A.m_columns != B.m_rows)
        {
            throw new GeometryException("Illegal matrix dimensions");
        }
        final Matrix C = new Matrix(A.m_rows, B.m_columns);

        for (int i = 0; i < C.m_rows; i++)
        {
            for (int j = 0; j < C.m_columns; j++)
            {
                for (int k = 0; k < A.m_columns; k++)
                {
                    C.m_data[i][j] += (A.m_data[i][k] * B.m_data[k][j]);
                }
            }
        }
        return C;
    }
181214
function() {
                	var matrix_rows = [];
                	var n = this.elements.length;
                	for (var i = 0; i < n; i++) {
                    matrix_rows.push(this.elements[i]);
                	}
                  return matrix_rows;
                }
337781
public Matrix times(Matrix B)
    {
        if (B.m != n)
        {
            throw new IllegalArgumentException("Matrix inner dimensions must agree.");
        }
        Matrix X = new Matrix(m, B.n);
        double[][] C = X.getArray();
        double[] Bcolj = new double[n];
        for (int j = 0; j < B.n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                Bcolj[k] = B.A[k][j];
            }
            for (int i = 0; i < m; i++)
            {
                double[] Arowi = A[i];
                double s = 0;
                for (int k = 0; k < n; k++)
                {
                    s += Arowi[k] * Bcolj[k];
                }
                C[i][j] = s;
            }
        }
        return X;
    }
1342442
public Matrix calcOrig() {
		if (!Coordinates.equals(getSource().getSize(), getSize())) {
			throw new RuntimeException(
					"Cannot change Matrix size. Use calc(Ret.NEW) or calc(Ret.LINK) instead.");
		}
		long[] newCoordinates = new long[position.length];
		for (long[] c : newContent.allCoordinates()) {
			Coordinates.plus(newCoordinates, position, c);
			getSource().setAsObject(getObject(newCoordinates), newCoordinates);
		}
		getSource().fireValueChanged();
		return getSource();
	}
1035851
private Matrix calculateV(IBasis basis) {
        int size = basis.getSize();
        Matrix V = new Matrix(size, size);
        int i, j;
        for (i = 0; i < size; i++)
            for (j = 0; j < size; j++)
                V.matrix[i][j] = basis.calcV(i, j);

        return V;
    }