/// <summary> /// Set this lower triangular matrix to the transpose of an upper triangular matrix /// </summary> /// <param name="U">The matrix to transpose</param> /// <returns></returns> public LowerTriangularMatrix SetToTranspose(UpperTriangularMatrix U) { if (rows != U.Cols || cols != U.Rows) { throw new ArgumentException("Output matrix is not compatible with the transpose", "that"); } U.CheckUpperTriangular(); // upper triangle of this is assumed to be zero for (int i = 0; i < rows; ++i) { for (int j = 0; j <= i; ++j) { this[i, j] = U[j, i]; } } CheckLowerTriangular(); return(this); }
/// <remarks>U is no longer a valid upper triangular matrix.</remarks> public static LowerTriangularMatrix TransposeInPlace(UpperTriangularMatrix U) { U.CheckUpperTriangular(); LowerTriangularMatrix L = new LowerTriangularMatrix(U.Cols, U.Rows, U.SourceArray, U.Start); Assert.IsTrue(L.Rows == L.Cols); for (int i = 0; i < L.Rows; ++i) { for (int j = 0; j < i; ++j) { L[i, j] = L[j, i]; L[j, i] = 0; } } L.CheckLowerTriangular(); return(L); }
/// <summary> /// Transposes a given lower triangular matrix in place. /// </summary> /// <param name="L">Matrix to transpose. Contents are corrupted on exit.</param> /// <returns>An upper triangular wrapper of L's source array.</returns> /// <remarks>L is no longer a valid lower triangular matrix.</remarks> public static UpperTriangularMatrix TransposeInPlace(LowerTriangularMatrix L) { L.CheckLowerTriangular(); UpperTriangularMatrix U = new UpperTriangularMatrix(L.Cols, L.Rows, L.SourceArray); Assert.IsTrue(U.Rows == U.Cols); for (int i = 0; i < U.Rows; ++i) { for (int j = i + 1; j < U.Cols; ++j) { U[i, j] = U[j, i]; U[j, i] = 0; } } U.CheckUpperTriangular(); return(U); }