/// <summary> /// Checks whether the given matrix <i>A</i> is <i>rectangular</i>. /// </summary> /// <param name="a"> /// The matrix. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// If <i>A.Rows < A.Columns</i>. /// </exception> public void CheckRectangular(DoubleMatrix2D a) { if (a.Rows < a.Columns) { throw new ArgumentOutOfRangeException("Matrix must be rectangular: " + AbstractFormatter.Shape(a)); } }
/// <summary> /// Checks whether the given matrix <i>A</i> is <i>rectangular</i>. /// </summary> /// <param name="a"> /// The matrix. /// </param> /// <exception cref="ArgumentOutOfRangeException"> /// If <i>A.Rows < A.Columns</i>. /// </exception> public void CheckRectangular(DoubleMatrix2D a) { if (a.Rows < a.Columns) { throw new ArgumentOutOfRangeException(String.Format(Cern.LocalizedResources.Instance().Exception_MatrixMustBeRectangular, AbstractFormatter.Shape(a))); } }
/// <summary> /// Sorts the matrix rows into ascending order, according to the <i>natural ordering</i> of the matrix values in the given column. /// </summary> /// <param name="matrix"> /// The matrix to be sorted. /// </param> /// <param name="column"> /// The index of the column inducing the order. /// </param> /// <returns> /// A new matrix view having rows sorted by the given column. /// </returns> /// <exception cref="IndexOutOfRangeException"> /// If <i>column < 0 || column >= matrix.columns()</i>. /// </exception> public DoubleMatrix2D Sort(DoubleMatrix2D matrix, int column) { if (column < 0 || column >= matrix.Columns) { throw new IndexOutOfRangeException("column=" + column + ", matrix=" + AbstractFormatter.Shape(matrix)); } var rowIndexes = new int[matrix.Rows]; // row indexes to reorder instead of matrix itself for (int i = rowIndexes.Length; --i >= 0;) { rowIndexes[i] = i; } DoubleMatrix1D col = matrix.ViewColumn(column); RunSort( rowIndexes, 0, rowIndexes.Length, (a, b) => { double av = col[a]; double bv = col[b]; if (Double.IsNaN(av) || Double.IsNaN(bv)) { return(CompareNaN(av, bv)); // swap NaNs to the end } return(av < bv ? -1 : (av == bv ? 0 : 1)); }); // view the matrix according to the reordered row indexes // take all columns in the original order return(matrix.ViewSelection(rowIndexes, null)); }