コード例 #1
0
        public void At(int i, int j, double value)
        {
            ContractAssertions.Requires <ArgumentOutOfRangeException>(i >= 0 && i <= rowCount, "Array Index out of bounds");
            ContractAssertions.Requires <ArgumentOutOfRangeException>(j >= 0 && j <= colCount, "Array Index out of bounds");
            int index = 0;

            if (val[i] == null)
            {
                val[i]          = new SparseRowValue[1];
                val[i][0].value = value;
                val[i][0].index = j;
                return;
            }

            index = Array.BinarySearch(val[i], 0, rowLength(i), j);

            if (index < 0)
            {
                if (value == 0.0d)
                {
                    return;
                }

                index = (index * -1) - 1;

                Array.Resize(ref val[i], val[i].Length + 1);


                // Array.Copy(val[i], index + 1, val[i], index + 2, (val[i].Length - index)+1);

                // Array.Resize(ref s, s.Length+1);

                for (int t = val[i].Length - 1; t > index; t--)
                {
                    val[i][t] = val[i][t - 1];
                }


                val[i][index].value = value;
                val[i][index].index = index;
                _NonZeroValueCount++;
            }
            else
            {
                //  If Value is zero then we must delete the entry
                if (value == 0)
                {
                    Array.Copy(val[i], index + 1, val[i], index, val[i].Length - index);
                    Array.Resize(ref val[i], val[i].Length - 1);
                    _NonZeroValueCount--;
                }
                else
                {
                    val[i][index].value = value;
                }
            }
        }
コード例 #2
0
        public void At(int i, int j, double value)
        {
            ContractAssertions.Requires <ArgumentOutOfRangeException>(i >= 0 && i <= rowCount, "Array Index out of bounds");
            ContractAssertions.Requires <ArgumentOutOfRangeException>(j >= 0 && j <= colCount, "Array Index out of bounds");
            int index = 0;

            index = Array.BinarySearch(val, rowPtr[i], rowLength(i), j);

            if (index < 0)
            {
                // TODO:  Need to insert value here
                // for efficiency should probably have a smaller array and merge periodically rather than all the time
                if (value == 0.0)
                {
                    return;
                }
                if (NonZeroValueCount == val.Length)
                {
                    // Need to resize the array as hit maximum size
                    Array.Resize(ref val, val.Length + ARRAYINCREMENT);
                }
                index = (index * -1) - 1;

                for (int t = rowPtr[rowCount]; t > index; t--)
                {
                    val[t] = val[t - 1];
                }
                for (int t = i + 1; t < rowCount + 1; t++)
                {
                    rowPtr[t]++;
                }

                val[index] = new SparseRowValue(j, value);
            }
            else
            {
                //  If Value is zero then we must delete the entry
                if (value == 0)
                {
                    for (int t = i + 1; t < rowCount + 1; t++)
                    {
                        rowPtr[t]--;
                    }

                    Array.Copy(val, index + 1, val, index, rowPtr[rowCount] - index);
                }
                else
                {
                    val[index].value = value;
                }
            }
        }
コード例 #3
0
        public void LoadRow(int row, int[] cols, double[] vals, int newRowLen)
        {
            bool checkSorted = true;

            for (int i = 1; i < newRowLen; i++)
            {
                if (cols[i - 1] > cols[i])
                {
                    checkSorted = false;
                }
            }

            if (!checkSorted)
            {
                throw new ArgumentException("Cols is not sorted");
            }

            //Console.WriteLine("here");

            if ((val.ContainsKey(row) && val[row].Length != 0) && _SequentialLoad == 0)
            {
                throw new ArgumentException("Row alreadys exists");
            }
            // Console.WriteLine("here");
            SparseRowValue[] rowArr = null;
            if (val.ContainsKey(row))
            {
                rowArr = val[row];
            }
            if (rowArr == null)
            {
                rowArr = new SparseRowValue[newRowLen];
            }
            else if (rowArr.Length < newRowLen)
            {
                Array.Resize(ref rowArr, newRowLen);
            }

            for (int j = 0; j < newRowLen; j++)
            {
                rowArr[j].index = cols[j];
                rowArr[j].value = vals[j];
            }
            val[row] = rowArr;
        }
コード例 #4
0
        public void LoadRow(int row, int[] cols, double[] vals, int newRowLen)
        {
            bool checkSorted = true;

            for (int i = 1; i < newRowLen; i++)
            {
                if (cols[i - 1] > cols[i])
                {
                    checkSorted = false;
                }
            }

            if (!checkSorted)
            {
                throw new ArgumentException("Cols is not sorted");
            }

            //Console.WriteLine("here");

            if ((val[row] != null && val[row].Length != 0) && _SequentialLoad == 0)
            {
                throw new ArgumentException("Row alreadys exists");
            }
            // Console.WriteLine("here");

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

            _NonZeroValueCount += newRowLen;
            for (int j = 0; j < newRowLen; j++)
            {
                val[row][j].index = cols[j];
                val[row][j].value = vals[j];
            }
        }