コード例 #1
0
        public static void CopyRow(SparseRowMatrixList to, int row, SparseRowMatrixList from, int fromRow)
        {
            int frl = from.rowLength(fromRow);

            if (frl == 0)
            {
                return;
            }

            //Console.WriteLine("Copyrow - "+ to.NonZeroValueCount+  " ," + to.val.Length +" ,"+ frl+" ,"+ (frl/ARRAYINCREMENT)  );
            if (!to.val.ContainsKey(row))
            {
                to.val.Add(row, new SparseRowValue[from.val[fromRow].Length]);
            }
            else if (to.val[row].Length < from.val[fromRow].Length)
            {
                SparseRowValue[] rowArr = to.val[row];
                Array.Resize(ref rowArr, from.val[fromRow].Length);
                to.val[row] = rowArr;
            }

            Array.Copy(from.val[fromRow], to.val[row], from.val[fromRow].Length);
        }
コード例 #2
0
        public SparseMatrix Transpose()
        {
            SparseRowMatrixList trans = new SparseRowMatrixList(colCount, rowCount);

            int[] rowCounts = new int[colCount];
            rowCounts.Initialize();

            for (int i = 0; i < rowCount; i++)
            {
                int len = (val.ContainsKey(i)) ? val[i].Length : 0;
                for (int j = 0; j < len; j++)
                {
                    rowCounts[val[i][j].index]++;
                }
            }

            for (int i = 0; i < colCount; i++)
            {
                trans.val[i] = new SparseRowValue[rowCounts[i]];
                rowCounts[i] = 0;
            }

            for (int i = 0; i < rowCount; i++)
            {
                int len = (val.ContainsKey(i)) ? val[i].Length : 0;
                for (int j = 0; j < len; j++)
                {
                    int col = val[i][j].index;
                    trans.val[col][rowCounts[col]].index = i;
                    trans.val[col][rowCounts[col]].value = val[i][j].value;
                    rowCounts[col]++;
                }
            }

            return(trans);
        }
コード例 #3
0
 public void CopyRow(int toRow, SparseMatrix from, int fromRow)
 {
     SparseRowMatrixList.CopyRow(this, toRow, (SparseRowMatrixList)from, fromRow);
 }