Esempio n. 1
0
        /// <summary>
        /// Creates a partition of positions in a collection of
        /// <see cref="DoubleMatrixRow"/>
        /// elements by
        /// aggregating those positions occupied by a same element.
        /// </summary>
        /// <param name="elements">The collection of rows whose
        /// positions are to be partitioned.</param>
        /// <example>
        /// <inheritdoc cref="IndexPartition"
        /// path="para[@id='IndexPartitionEx1Intro']"/>
        /// <inheritdoc cref="IndexPartition"
        /// path="para[@id='IndexPartitionEx1Code']"/>
        /// </example>
        /// <returns>The partition of row indexes in the
        /// specified collection.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="elements"/> is <b>null</b>.
        /// </exception>
        public static IndexPartition <DoubleMatrixRow> Create(
            DoubleMatrixRowCollection elements)
        {
            if (elements is null)
            {
                throw new ArgumentNullException(nameof(elements));
            }

            SortedSet <DoubleMatrixRow> distinctElements =
                new();
            Dictionary <DoubleMatrixRow, List <int> > indexLists =
                new();

            bool isNotAlreadyInElementSet;
            int  i = 0;

            foreach (var row in elements)
            {
                isNotAlreadyInElementSet = distinctElements.Add(row);
                if (isNotAlreadyInElementSet)
                {
                    indexLists.Add(row, new List <int>());
                }

                indexLists[row].Add(i);
                i++;
            }

            IndexPartition <DoubleMatrixRow> partition =
                new();

            foreach (var element in distinctElements)
            {
                partition[element] = new IndexCollection(
                    indexLists[element].ToArray(), false);
                partition.partIndetifiers.Add(element);
            }

            return(partition);
        }
Esempio n. 2
0
 /// <summary>
 /// Converts
 /// from <see cref="DoubleMatrixRowCollection"/> to <see cref="DoubleMatrix"/>.
 /// </summary>
 /// <param name="value">The object to convert.</param>
 /// <returns>The converted object.</returns>
 public static DoubleMatrix ToDoubleMatrix(DoubleMatrixRowCollection value)
 {
     return(value);
 }