internal IntensityMatrix Subset(Predicate <Peak> peakFilter, Predicate <ObservationInfo> columnFilter, ESubsetFlags flags) { // Get the ROWS involved in the subset int[] rowIndices; if (flags.Has(ESubsetFlags.InvertPeakFilter)) { // Inverted filter if (peakFilter == null) { rowIndices = new int[0]; } else { rowIndices = this.Rows.Which(z => !peakFilter(z.Peak)).ToArray(); } } else { if (peakFilter == null) { rowIndices = this.Rows.Indices().ToArray(); } else { rowIndices = this.Rows.Which(z => peakFilter(z.Peak)).ToArray(); } } // Get the ROW HEADERS RowHeader[] newRows = this.Rows.At(rowIndices).ToArray(); // Get the column indices int[] colIndices = (columnFilter != null)? this.Columns.Which(z => columnFilter(z.Observation)).ToArray() : this.Columns.Indices().ToArray(); // Get the COLUMN HEADERS ColumnHeader[] newCols = this.Columns.At(colIndices).ToArray(); // Get the VALUES double[,] newValues = new double[rowIndices.Length, colIndices.Length]; for (int row = 0; row < rowIndices.Length; ++row) { int origRowIndex = rowIndices[row]; for (int col = 0; col < colIndices.Length; ++col) { int origColIndex = colIndices[col]; newValues[row, col] = Values[origRowIndex, origColIndex]; } } // Return the result return(new IntensityMatrix(newRows, newCols, newValues)); }
internal IntensityMatrix Subset(PeakFilter peakFilter, ObsFilter columnFilter, ESubsetFlags flags) { return(this.Subset(peakFilter != null ? (Predicate <Peak>)peakFilter.Test : null, columnFilter != null ? (Predicate <ObservationInfo>)columnFilter.Test : null, flags)); }