コード例 #1
0
ファイル: SparseMatrix.cs プロジェクト: 0000duck/latino
        public void Symmetrize(Utils.BinaryOperatorDelegate <T> binOp)
        {
            SparseMatrix <T> trMat = GetTransposedCopy();

            trMat.RemoveDiagonal();
            trMat.MergeSym(this, binOp); // throws ArgumentNullException
            mRows = trMat.mRows;
        }
コード例 #2
0
ファイル: SparseMatrix.cs プロジェクト: 0000duck/latino
        private void MergeSym(SparseMatrix <T> otherMatrix, Utils.BinaryOperatorDelegate <T> binaryOperator)
        {
            int otherMatrixNumRows = otherMatrix.GetLastNonEmptyRowIdx() + 1;

            if (mRows.Count < otherMatrixNumRows)
            {
                SetRowListSize(otherMatrixNumRows);
            }
            for (int rowIdx = 0; rowIdx < otherMatrixNumRows; rowIdx++)
            {
                mRows[rowIdx] = MergeRowsSym(mRows[rowIdx], otherMatrix.mRows[rowIdx], binaryOperator, rowIdx);
            }
        }
コード例 #3
0
ファイル: SparseMatrix.cs プロジェクト: 0000duck/latino
        public void Merge(SparseMatrix <T> otherMatrix, Utils.BinaryOperatorDelegate <T> binaryOperator)
        {
            Utils.ThrowException(binaryOperator == null ? new ArgumentNullException("binaryOperator") : null);
            int otherMatrixNumRows = otherMatrix.GetLastNonEmptyRowIdx() + 1;

            if (mRows.Count < otherMatrixNumRows)
            {
                SetRowListSize(otherMatrixNumRows);
            }
            for (int rowIdx = 0; rowIdx < otherMatrixNumRows; rowIdx++)
            {
                mRows[rowIdx].Merge(otherMatrix.mRows[rowIdx], binaryOperator);
            }
        }
コード例 #4
0
        public void Merge(SparseVector <T> otherVec, Utils.BinaryOperatorDelegate <T> binaryOperator)
        {
            Utils.ThrowException(otherVec == null ? new ArgumentNullException("otherVec") : null);
            Utils.ThrowException(binaryOperator == null ? new ArgumentNullException("binaryOperator") : null);
            ArrayList <int> otherIdx = otherVec.InnerIdx;
            ArrayList <T>   otherDat = otherVec.InnerDat;
            ArrayList <int> newIdx = new ArrayList <int>(mIdx.Count + otherIdx.Count);
            ArrayList <T>   newDat = new ArrayList <T>(mDat.Count + otherDat.Count);
            int             i = 0, j = 0;

            while (i < mIdx.Count && j < otherIdx.Count)
            {
                int aIdx = mIdx[i];
                int bIdx = otherIdx[j];
                if (aIdx == bIdx)
                {
                    T value = binaryOperator(mDat[i], otherDat[j]);
                    if (value != null)
                    {
                        newIdx.Add(aIdx); newDat.Add(value);
                    }
                    i++;
                    j++;
                }
                else if (aIdx < bIdx)
                {
                    newIdx.Add(aIdx); newDat.Add(mDat[i]);
                    i++;
                }
                else
                {
                    newIdx.Add(bIdx); newDat.Add(otherDat[j]);
                    j++;
                }
            }
            for (; i < mIdx.Count; i++)
            {
                newIdx.Add(mIdx[i]); newDat.Add(mDat[i]);
            }
            for (; j < otherIdx.Count; j++)
            {
                newIdx.Add(otherIdx[j]); newDat.Add(otherDat[j]);
            }
            mIdx = newIdx;
            mDat = newDat;
        }
コード例 #5
0
 public void Merge(SparseVector <T> .ReadOnly otherVec, Utils.BinaryOperatorDelegate <T> binaryOperator)
 {
     Utils.ThrowException(otherVec == null ? new ArgumentNullException("otherVec") : null);
     Merge(otherVec.Inner, binaryOperator); // throws ArgumentNullException
 }
コード例 #6
0
 public void ToUndirected(Utils.BinaryOperatorDelegate <EdgeT> binOp)
 {
     mMtx.Symmetrize(binOp); // throws ArgumentNullException
 }
コード例 #7
0
ファイル: SparseMatrix.cs プロジェクト: 0000duck/latino
        private SparseVector <T> MergeRowsSym(SparseVector <T> row, SparseVector <T> otherRow, Utils.BinaryOperatorDelegate <T> binaryOperator, int rowIdx)
        {
            SparseVector <T> newRow   = new SparseVector <T>();
            ArrayList <int>  idx      = row.InnerIdx;
            ArrayList <T>    dat      = row.InnerDat;
            ArrayList <int>  otherIdx = otherRow.InnerIdx;
            ArrayList <T>    otherDat = otherRow.InnerDat;

            newRow.InnerIdx.Capacity = idx.Count + otherIdx.Count;
            newRow.InnerDat.Capacity = dat.Count + otherDat.Count;
            ArrayList <int> newIdx = newRow.InnerIdx;
            ArrayList <T>   newDat = newRow.InnerDat;
            int             i = 0, j = 0;

            while (i < idx.Count && j < otherIdx.Count)
            {
                int aIdx = idx[i];
                int bIdx = otherIdx[j];
                if (aIdx == bIdx)
                {
                    T value;
                    if (aIdx < rowIdx)
                    {
                        value = binaryOperator(dat[i], otherDat[j]);
                    }
                    else
                    {
                        value = binaryOperator(otherDat[j], dat[i]);
                    }
                    if (value != null)
                    {
                        newIdx.Add(aIdx); newDat.Add(value);
                    }
                    i++;
                    j++;
                }
                else if (aIdx < bIdx)
                {
                    newIdx.Add(aIdx); newDat.Add(dat[i]);
                    i++;
                }
                else
                {
                    newIdx.Add(bIdx); newDat.Add(otherDat[j]);
                    j++;
                }
            }
            for (; i < idx.Count; i++)
            {
                newIdx.Add(idx[i]); newDat.Add(dat[i]);
            }
            for (; j < otherIdx.Count; j++)
            {
                newIdx.Add(otherIdx[j]); newDat.Add(otherDat[j]);
            }
            return(newRow);
        }
コード例 #8
0
ファイル: SparseMatrix.cs プロジェクト: 0000duck/latino
 public void Merge(SparseMatrix <T> .ReadOnly otherMatrix, Utils.BinaryOperatorDelegate <T> binaryOperator)
 {
     Merge(otherMatrix.Inner, binaryOperator); // throws ArgumentNullException
 }