public SparseMatrix Transpose()
        {
            SparseRowMatrixVN trans = new SparseRowMatrixVN(colCount, rowCount);

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

            for (int i = 0; i < NonZeroValueCount; i++)
            {
                rowCounts[val[i].index]++;
            }

            int y = 0;
            int t = 0;

            for (int i = 0; i < colCount; i++)
            {
                trans.rowPtr[i] = y;
                t            = y;
                y           += rowCounts[i];
                rowCounts[i] = t;
            }
            trans.rowPtr[colCount] = y;

            trans.val = new SparseRowValue[y];
            for (int i = 0; i < rowCount; i++)
            {
                for (int j = rowPtr[i]; j < rowPtr[i + 1]; j++)
                {
                    trans.val[rowCounts[val[j].index]++].set(i, val[j].value);
                }
            }

            return(trans);
        }
        public static void CopyRow(SparseRowMatrixVN to, int row, SparseRowMatrixVN 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.NonZeroValueCount + frl > to.val.Length)
            {
                // Need to resize the array as hit maximum size
                Array.Resize(ref to.val, to.val.Length + (frl > ARRAYINCREMENT ? ((frl / ARRAYINCREMENT) + 1) * ARRAYINCREMENT : ARRAYINCREMENT));
            }

            if (to.rowPtr[row] == to.NonZeroValueCount)
            {
                // points to the end of the array so can just append all the rows
                int trow = to.rowPtr[row];
                IEnumerable <SparseRowValue> f = from.getRow(fromRow);

                foreach (SparseRowValue fi in f)
                {
                    to.val[trow++] = fi;
                }

                for (int i = row + 1; i <= to.rowCount; i++)
                {
                    to.rowPtr[i] = trow;
                }
            }
            else
            {
                // Need to insert frl rows
                int trow = to.rowPtr[row];
                for (int t = to.rowPtr[to.rowCount]; t > trow; t--)
                {
                    to.val[t] = to.val[t - 1];
                }

                IEnumerable <SparseRowValue> f = from.getRow(fromRow);

                foreach (SparseRowValue fi in f)
                {
                    to.val[trow++] = fi;
                }

                for (int i = row + 1; i <= to.rowCount; i++)
                {
                    to.rowPtr[i] += frl;
                }
            }
        }
 public void CopyRow(int toRow, SparseMatrix from, int fromRow)
 {
     SparseRowMatrixVN.CopyRow(this, toRow, (SparseRowMatrixVN)from, fromRow);
 }