示例#1
0
 private SymmetricMatrix(double[] data, int order, DefiniteProperty definiteness)
 {
     this.data         = data;
     this.Definiteness = definiteness;
     this.Order        = order;
     this.NumRows      = order;
     this.NumColumns   = order;
 }
示例#2
0
        /// <summary>
        /// Create a new <see cref="SymmetricMatrix"/> from a provided array. The array can be copied (for extra safety)
        /// or not (for extra performance).
        /// </summary>
        /// <param name="array1D">A 1-dimensional array containing the elements of the upper triangle of the matrix in row
        ///     major order.</param>
        /// <param name="order"> The order of the matrix. It must be positive and match the length of <see cref="array1D"/>. If a
        ///     value is provided, these will not be checked. If no value is provided, the order will be calculated from
        ///     <see cref="array1D"/> instead.</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>
        public static SymmetricMatrix CreateFromPackedRowMajorArray(double[] array1D, int order   = 0,
                                                                    DefiniteProperty definiteness = DefiniteProperty.Unknown)
        {
            int n = (order == 0) ? Conversions.PackedLengthToOrder(array1D.Length) : order;

            double[] columnMajor = Conversions.PackedUpperRowMajorPackedUpperColMajor(n, array1D);
            return(new SymmetricMatrix(columnMajor, n, definiteness));
        }
示例#3
0
        /// <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));
        }
示例#4
0
        /// <summary>
        /// Create a new <see cref="SymmetricMatrix"/> from a provided array. The array can be copied (for extra safety)
        /// or not (for extra performance).
        /// </summary>
        /// <param name="array1D">A 1-dimensional array containing the elements of the upper triangle of the matrix in column
        ///     major order.</param>
        /// <param name="order"> The order of the matrix. It must be positive and match the length of <see cref="array1D"/>. If a
        ///     value is provided, these will not be checked. If no value is provided, the order will be calculated from
        ///     <see cref="array1D"/> instead.</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>
        /// <param name="copyArray">True to make a deep copy of <see cref="array1D"/>.
        ///     False (default) to use <see cref="array1D"/> as its internal storage.</param>
        public static SymmetricMatrix CreateFromPackedColumnMajorArray(double[] array1D, int order   = 0,
                                                                       DefiniteProperty definiteness = DefiniteProperty.Unknown, bool copyArray = false)
        {
            int n = (order == 0) ? Conversions.PackedLengthToOrder(array1D.Length) : order;

            if (copyArray)
            {
                var clone = new double[array1D.Length];
                Array.Copy(array1D, clone, array1D.Length);
                return(new SymmetricMatrix(clone, n, definiteness));
            }
            else
            {
                return(new SymmetricMatrix(array1D, n, definiteness));
            }
        }