/// <summary> /// Initializes a new instance of <see cref="TriangularUpper"/> by copying the upper triangle of the provided 2D array. /// </summary> /// <param name="array2D">A 2-dimensional array containing the elements of the matrix. Constraints: /// <paramref name="array2D"/>.GetLength(0) == <paramref name="array2D"/>.GetLength(1).</param> /// <exception cref="NonMatchingDimensionsException">Thrown if <paramref name="array2D"/>.GetLength(0) != /// <paramref name="array2D"/>.GetLength(1).</exception> public static TriangularUpper CreateFromArray(double[,] array2D) { int numRows = array2D.GetLength(0); int numCols = array2D.GetLength(1); if (numRows != numCols) { string msg = $"Provided array must have the same dimensions, but was ({numRows}x{numCols})"; throw new NonMatchingDimensionsException(msg); } return(new TriangularUpper(Conversions.Array2DToPackedUpperColMajor(array2D), numRows)); }
/// <summary> /// Create a new <see cref="SymmetricMatrix"/> from the lower (subdiagonal) or upper (superdiagonal) portion of the /// provided array. The array entries will be copied. /// </summary> /// <param name="array2D">A 2-dimensional containing the elements of the whole matrix. Its lengths in both dimensions /// must be the same.</param> /// <param name="definiteness">If the caller knows that the matrix is positive definite, etc, he can set this property /// during creation of the <see cref="SymmetricMatrix"/> object.</param> /// <returns></returns> public static SymmetricMatrix CreateFromArray(double[,] array2D, DefiniteProperty definiteness = DefiniteProperty.Unknown) { int numRows = array2D.GetLength(0); int numCols = array2D.GetLength(1); if (numRows != numCols) { string msg = string.Format("Provided array must have the same dimensions, but was ({0}x{1})", numRows, numCols); throw new NonMatchingDimensionsException(msg); } return(new SymmetricMatrix(Conversions.Array2DToPackedUpperColMajor(array2D), numRows, definiteness)); }