Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="KeyedMatrix{TKey}" /> class.
        /// </summary>
        /// <param name="matrix">The matrix which holds the keys and data to copy into this new matrix</param>
        protected KeyedRowColumnMatrix(IList <TRowKey> rowKeys, IList <TColumnKey> columnKeys, KeyedRowColumnMatrix <TRowKey, TColumnKey> matrix)
        {
            IEnumerable <TRowKey>    unionOfRowKeys    = rowKeys.Union(matrix.RowKeys);
            IEnumerable <TColumnKey> unionOfColumnKeys = columnKeys.Union(matrix.ColumnKeys);

            this.CheckAndAddKeys(unionOfRowKeys, unionOfColumnKeys);
            foreach (TRowKey rowKey in matrix.RowKeys)
            {
                foreach (TColumnKey columnKey in matrix.ColumnKeys)
                {
                    this.At(rowKey, columnKey, matrix.At(rowKey, columnKey));
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a matrix which contains values from the requested sub-matrix
        /// </summary>
        /// <param name="rowsToInclude">A list of the keys of rows to include in the new matrix</param>
        /// <param name="columnsToInclude">A list of the keys of columns to include in the new matrix</param>
        /// <returns>A KeyedMatrix which contains values from the requested sub-matrix</returns>
        public KeyedRowColumnMatrix <TRowKey, TColumnKey> SubMatrix(IList <TRowKey> rowsToInclude, IList <TColumnKey> columnsToInclude)
        {
            KeyedRowColumnMatrix <TRowKey, TColumnKey> subMatrix = new KeyedRowColumnMatrix <TRowKey, TColumnKey>(rowsToInclude, columnsToInclude);

            foreach (TRowKey rowKey in rowsToInclude)
            {
                foreach (TColumnKey columnKey in columnsToInclude)
                {
                    subMatrix.At(rowKey, columnKey, this.At(rowKey, columnKey));
                }
            }

            return(subMatrix);
        }