Invert by solving for against an identity matrix.

@param A_inv Where the inverted matrix saved. Modified.
518700
@Override
    public void invert(DMatrixRBlock A_inv) {
        int M = Math.min(QR.numRows,QR.numCols);
        if( A_inv.numRows != M || A_inv.numCols != M )
            throw new IllegalArgumentException("A_inv must be square an have dimension "+M);


        // Solve for A^-1
        // Q*R*A^-1 = I

        // Apply householder reflectors to the identity matrix
        // y = Q^T*I = Q^T
        MatrixOps_DDRB.setIdentity(A_inv);
        decomposer.applyQTran(A_inv);

        // Solve using upper triangular R matrix
        // R*A^-1 = y
        // A^-1 = R^-1*y
        TriangularSolver_DDRB.solve(QR.blockLength,true,
                new DSubmatrixD1(QR,0,M,0,M),new DSubmatrixD1(A_inv),false);
    }
1314055
def invert_affine_mat44(mat):
    

    inverted = Matrix44()

    # Transpose the 3x3 rotation component
    for i in range(3):
        for j in range(3):
            inverted.data[i][j] = mat.data[j][i]

    # Set translation: inverted_trans_vec3 = -inv(rot_mat33) * trans_vec3
    for row in range(3):
        inverted.data[3][row] = (
            -inverted.data[0][row] * mat.data[3][0] +
            -inverted.data[1][row] * mat.data[3][1] +
            -inverted.data[2][row] * mat.data[3][2])

    return inverted
712505
@Override
    public boolean invert() {
        double determinant = determinant();
        if (determinant == 0) {
            return false;
        }

        // first row
        double t00 =  determinant3x3(m11, m12, m13, m21, m22, m23, m31, m32, m33);
        double t01 = -determinant3x3(m10, m12, m13, m20, m22, m23, m30, m32, m33);
        double t02 =  determinant3x3(m10, m11, m13, m20, m21, m23, m30, m31, m33);
        double t03 = -determinant3x3(m10, m11, m12, m20, m21, m22, m30, m31, m32);

        // second row
        double t10 = -determinant3x3(m01, m02, m03, m21, m22, m23, m31, m32, m33);
        double t11 =  determinant3x3(m00, m02, m03, m20, m22, m23, m30, m32, m33);
        double t12 = -determinant3x3(m00, m01, m03, m20, m21, m23, m30, m31, m33);
        double t13 =  determinant3x3(m00, m01, m02, m20, m21, m22, m30, m31, m32);

        // third row
        double t20 =  determinant3x3(m01, m02, m03, m11, m12, m13, m31, m32, m33);
        double t21 = -determinant3x3(m00, m02, m03, m10, m12, m13, m30, m32, m33);
        double t22 =  determinant3x3(m00, m01, m03, m10, m11, m13, m30, m31, m33);
        double t23 = -determinant3x3(m00, m01, m02, m10, m11, m12, m30, m31, m32);

        // fourth row
        double t30 = -determinant3x3(m01, m02, m03, m11, m12, m13, m21, m22, m23);
        double t31 =  determinant3x3(m00, m02, m03, m10, m12, m13, m20, m22, m23);
        double t32 = -determinant3x3(m00, m01, m03, m10, m11, m13, m20, m21, m23);
        double t33 =  determinant3x3(m00, m01, m02, m10, m11, m12, m20, m21, m22);

        // transpose and divide by the determinant
        m00 = t00 / determinant;
        m01 = t10 / determinant;
        m02 = t20 / determinant;
        m03 = t30 / determinant;

        m10 = t01 / determinant;
        m11 = t11 / determinant;
        m12 = t21 / determinant;
        m13 = t31 / determinant;

        m20 = t02 / determinant;
        m21 = t12 / determinant;
        m22 = t22 / determinant;
        m23 = t32 / determinant;

        m30 = t03 / determinant;
        m31 = t13 / determinant;
        m32 = t23 / determinant;
        m33 = t33 / determinant;

        return true;
    }
111486
function (projectionMatrix) {
        Matrix4.copy(this.projectionMatrix, projectionMatrix);
        Matrix4.invert(this.invProjectionMatrix, projectionMatrix);
        this.decomposeProjectionMatrix();
    }
457400
public static void changeSign( DMatrix5 a )
    {
        a.a1 = -a.a1;
        a.a2 = -a.a2;
        a.a3 = -a.a3;
        a.a4 = -a.a4;
        a.a5 = -a.a5;
    }
958770
public Matrix4x3f invertOrtho(Matrix4x3f dest) {
        float invM00 = 1.0f / m00;
        float invM11 = 1.0f / m11;
        float invM22 = 1.0f / m22;
        dest.set(invM00, 0, 0,
                 0, invM11, 0,
                 0, 0, invM22,
                 -m30 * invM00, -m31 * invM11, -m32 * invM22);
        dest.properties = 0;
        return dest;
    }
960190
public static void flip( int []a , int N ) {
		int H = N/2;

		for (int i = 1; i <= H; i++) {
			int j = N-i;
			int tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}
	}
74763
private static Map<TypeVariable<?>, Type> invert(Map<TypeVariable<?>, Type> m) {
        final TypeVariableMap result = new TypeVariableMap();
        for (Map.Entry<TypeVariable<?>, Type> e : m.entrySet()) {
            if (e.getValue() instanceof TypeVariable<?>) {
                result.put((TypeVariable<?>) e.getValue(), e.getKey());
            }
        }
        return result;
    }
286677
def inverted(self):
        
        out = self.copy()
        out.setInverted(not self.isInverted())
        return out
834516
def MatrixInverse(a, adj):
    
    return np.linalg.inv(a if not adj else _adjoint(a)),
452618
def inv_n(x):
    ''''''
    #
    # The inverse of a small matrix (e.g. 3x3) is
    #
    #   1
    # -----   C(j,i)
    # det(A)
    #
    # where C(j,i) is the cofactor of matrix A at position j,i
    #
    assert x.ndim == 3
    assert x.shape[1] == x.shape[2]
    c = np.array([ [cofactor_n(x, j, i) * (1 - ((i+j) % 2)*2)
                    for j in range(x.shape[1])]
                   for i in range(x.shape[1])]).transpose(2,0,1)
    return c / det_n(x)[:, np.newaxis, np.newaxis]
599040
public AFPChain invertAlignment(AFPChain a) {
		String name1 = a.getName1();
		String name2 = a.getName2();
		a.setName1(name2);
		a.setName2(name1);

		int len1 = a.getCa1Length();
		a.setCa1Length( a.getCa2Length() );
		a.setCa2Length( len1 );

		int beg1 = a.getAlnbeg1();
		a.setAlnbeg1(a.getAlnbeg2());
		a.setAlnbeg2(beg1);

		char[] alnseq1 = a.getAlnseq1();
		a.setAlnseq1(a.getAlnseq2());
		a.setAlnseq2(alnseq1);

		Matrix distab1 = a.getDisTable1();
		a.setDisTable1(a.getDisTable2());
		a.setDisTable2(distab1);

		int[] focusRes1 = a.getFocusRes1();
		a.setFocusRes1(a.getFocusRes2());
		a.setFocusRes2(focusRes1);

		//What are aftIndex and befIndex used for? How are they indexed?
		//a.getAfpAftIndex()


		String[][][] pdbAln = a.getPdbAln();
		if( pdbAln != null) {
			for(int block = 0; block < a.getBlockNum(); block++) {
				String[] paln1 = pdbAln[block][0];
				pdbAln[block][0] = pdbAln[block][1];
				pdbAln[block][1] = paln1;
			}
		}

		int[][][] optAln = a.getOptAln();
		if( optAln != null ) {
			for(int block = 0; block < a.getBlockNum(); block++) {
				int[] aln1 = optAln[block][0];
				optAln[block][0] = optAln[block][1];
				optAln[block][1] = aln1;
			}
		}
		a.setOptAln(optAln); // triggers invalidate()

		Matrix distmat = a.getDistanceMatrix();
		if(distmat != null)
			a.setDistanceMatrix(distmat.transpose());


		// invert the rotation matrices
		Matrix[] blockRotMat = a.getBlockRotationMatrix();
		Atom[] shiftVec = a.getBlockShiftVector();
		if( blockRotMat != null) {
			for(int block = 0; block < a.getBlockNum(); block++) {
				if(blockRotMat[block] != null) {
					// if y=x*A+b, then x=y*inv(A)-b*inv(A)
					blockRotMat[block] = blockRotMat[block].inverse();

					Calc.rotate(shiftVec[block],blockRotMat[block]);
					shiftVec[block] = Calc.invert(shiftVec[block]);
				}
			}
		}

		return a;
	}
561310
public static void changeSign( DMatrix3x3 a )
    {
        a.a11 = -a.a11; a.a12 = -a.a12; a.a13 = -a.a13;
        a.a21 = -a.a21; a.a22 = -a.a22; a.a23 = -a.a23;
        a.a31 = -a.a31; a.a32 = -a.a32; a.a33 = -a.a33;
    }
681606
public Matrix3x2d invert(Matrix3x2d dest) {
        // client must make sure that matrix is invertible
        double s = 1.0 / (m00 * m11 - m01 * m10);
        double nm00 =  m11 * s;
        double nm01 = -m01 * s;
        double nm10 = -m10 * s;
        double nm11 =  m00 * s;
        double nm20 = (m10 * m21 - m20 * m11) * s;
        double nm21 = (m20 * m01 - m00 * m21) * s;
        dest.m00 = nm00;
        dest.m01 = nm01;
        dest.m10 = nm10;
        dest.m11 = nm11;
        dest.m20 = nm20;
        dest.m21 = nm21;
        return dest;
    }
931379
public Matrix4f invertAffine(Matrix4f dest) {
        float m11m00 = m00 * m11, m10m01 = m01 * m10, m10m02 = m02 * m10;
        float m12m00 = m00 * m12, m12m01 = m01 * m12, m11m02 = m02 * m11;
        float det = (m11m00 - m10m01) * m22 + (m10m02 - m12m00) * m21 + (m12m01 - m11m02) * m20;
        float s = 1.0f / det;
        float nm00, nm01, nm02, nm10, nm11, nm12, nm20, nm21, nm22, nm30, nm31, nm32;
        float m10m22 = m10 * m22, m10m21 = m10 * m21, m11m22 = m11 * m22;
        float m11m20 = m11 * m20, m12m21 = m12 * m21, m12m20 = m12 * m20;
        float m20m02 = m20 * m02, m20m01 = m20 * m01, m21m02 = m21 * m02;
        float m21m00 = m21 * m00, m22m01 = m22 * m01, m22m00 = m22 * m00;
        nm00 = (m11m22 - m12m21) * s;
        nm01 = (m21m02 - m22m01) * s;
        nm02 = (m12m01 - m11m02) * s;
        nm10 = (m12m20 - m10m22) * s;
        nm11 = (m22m00 - m20m02) * s;
        nm12 = (m10m02 - m12m00) * s;
        nm20 = (m10m21 - m11m20) * s;
        nm21 = (m20m01 - m21m00) * s;
        nm22 = (m11m00 - m10m01) * s;
        nm30 = (m10m22 * m31 - m10m21 * m32 + m11m20 * m32 - m11m22 * m30 + m12m21 * m30 - m12m20 * m31) * s;
        nm31 = (m20m02 * m31 - m20m01 * m32 + m21m00 * m32 - m21m02 * m30 + m22m01 * m30 - m22m00 * m31) * s;
        nm32 = (m11m02 * m30 - m12m01 * m30 + m12m00 * m31 - m10m02 * m31 + m10m01 * m32 - m11m00 * m32) * s;
        dest._m00(nm00);
        dest._m01(nm01);
        dest._m02(nm02);
        dest._m03(0.0f);
        dest._m10(nm10);
        dest._m11(nm11);
        dest._m12(nm12);
        dest._m13(0.0f);
        dest._m20(nm20);
        dest._m21(nm21);
        dest._m22(nm22);
        dest._m23(0.0f);
        dest._m30(nm30);
        dest._m31(nm31);
        dest._m32(nm32);
        dest._m33(1.0f);
        dest._properties(PROPERTY_AFFINE);
        return dest;
    }
726714
public function Invert($a, $b)
    {
        $this->preOpMethodParamsCheck(array($a, $b));

        return $this->math->inv($a, $b);
    }
173764
private static int[] inverse(int[] perm) {
        int[] inv = new int[perm.length];
        for (int i = 0, len = perm.length; i < len; i++)
            inv[perm[i]] = i;
        return inv;
    }