Exemplo n.º 1
0
        public static void CopyRow(SparseRowMatrixArr to, int row, SparseRowMatrixArr from, int fromRow)
        {
            int frl = from.rowLength(fromRow);

            if (frl == 0)
            {
                return;
            }

            if (to.val[row] == null)
            {
                to.val[row] = new SparseRowValue[frl];
            }
            else if (to.val[row].Length != frl)
            {
                Array.Resize(ref to.val[row], frl);
            }

            Array.Copy(from.val[fromRow], to.val[row], frl);
        }
Exemplo n.º 2
0
        public SparseMatrix Transpose()
        {
            SparseRowMatrixArr trans = new SparseRowMatrixArr(colCount, rowCount);

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

            for (int i = 0; i < rowCount; i++)
            {
                int len = (val[i] == null) ? 0 : val[i].Length;
                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 < val.Length; i++)
            {
                int len = (val[i] == null) ? 0 : val[i].Length;
                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);
        }
Exemplo n.º 3
0
 public void CopyRow(int toRow, SparseMatrix from, int fromRow)
 {
     SparseRowMatrixArr.CopyRow(this, toRow, (SparseRowMatrixArr)from, fromRow);
 }