当前位置: 首页>>代码示例>>C#>>正文


C# SparseMatrix.IsSymmetric方法代码示例

本文整理汇总了C#中SparseMatrix.IsSymmetric方法的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix.IsSymmetric方法的具体用法?C# SparseMatrix.IsSymmetric怎么用?C# SparseMatrix.IsSymmetric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SparseMatrix的用法示例。


在下文中一共展示了SparseMatrix.IsSymmetric方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateMatrixATA

        public static SparseMatrix CreateMatrixATA(ref SparseMatrix A,ref NonManifoldMesh mesh)
        {
            // assume A is sorted
            // assume values in parameter adj is in order

            if (A == null)
                throw new Exception("A matrix is null");

            int[][] adj = MeshOperators.BuildTwoRingVV(ref mesh).GetRowIndex();
            int n = A.ColumnSize;
            SparseMatrix ATA = new SparseMatrix(n, n);

            for (int i = 0; i < n; i++)
            {
                List<SparseMatrix.Element> col1 = A.GetColumn(i);
                foreach (int j in adj[i])
                {
                    List<SparseMatrix.Element> col2 = A.GetColumn(j);
                    int c1 = 0, c2 = 0;
                    double sum = 0.0;
                    bool used = false;

                    while (c1 < col1.Count && c2 < col2.Count)
                    {
                        if (col1[c1].i < col2[c2].i) { c1++; continue; }
                        if (col1[c1].i > col2[c2].i) { c2++; continue; }
                        sum += col1[c1].value * col2[c2].value;
                        used = true;
                        c1++;
                        c2++;
                    }

                    if (used)
                        ATA.AddElement(i, j, sum);
                }
            }

            if (ATA.IsSymmetric() == false) throw new Exception("ATA is not symmetric!!");
            return ATA;
        }      
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:40,代码来源:MeshOperators.cs

示例2: InitMatrixType

        private void InitMatrixType()
        {
            SparseMatrix matrix = null;
            this.dataGridViewType.Rows.Clear();
            int index=0;
            foreach (EnumLaplaceMatrix type in Enum.GetValues(typeof(EnumLaplaceMatrix)))
            { 
                matrix = LaplaceManager.Instance.GenerateLaplaceMatrix(type, Mesh);

                if (matrix != null)
                {
                    this.dataGridViewType.Rows.Add(index, type, matrix.ColumnSize, matrix.RowSize, matrix.NumOfElements(),
                                                   matrix.ZeroSize, matrix.WholeSize, matrix.IsSymmetric());

                    index++;
                }
            }
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:18,代码来源:FormEigenMatrix.cs

示例3: WriteMatrix

        private static void WriteMatrix(SparseMatrix sparseMatrix, string path)
        {
            StreamWriter sw;
            sw = File.CreateText(path);


            int lineCount = 0;
            bool symmetric = sparseMatrix.IsSymmetric();

            //Get NoneOfZeroCount
            foreach (List<SparseMatrix.Element> col in sparseMatrix.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (!symmetric && e.value != 0)
                    {
                        lineCount++;
                    }

                    if (symmetric && e.i >= e.j && e.value != 0)
                    {
                        lineCount++;
                    }
                }
            }


            //Output matrix attributes
            sw.WriteLine("#Row: " + sparseMatrix.RowSize + " Columns: " + sparseMatrix.ColumnSize + " nnz: " + lineCount);

            if (symmetric)
            {
                sw.WriteLine("#Symmetric: true L");
            }
            else
            {
                sw.WriteLine("#Symmetric: false N");
            }

            int z = 0;
            foreach (List<SparseMatrix.Element> col in sparseMatrix.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (!symmetric && e.value != 0)
                    {
                        z++;
                        if (z != lineCount)
                            sw.WriteLine(e.i + " " + e.j + " " + e.value);
                        else
                            sw.Write(e.i + " " + e.j + " " + e.value);
                    }

                    if (symmetric && e.i >= e.j && e.value != 0)
                    {
                        z++;
                        if (z != lineCount)
                            sw.WriteLine(e.i + " " + e.j + " " + e.value);
                        else
                            sw.Write(e.i + " " + e.j + " " + e.value);
                    }
                }
            }

            sw.Close();
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:66,代码来源:IOHuizhao.cs

示例4: Main


//.........这里部分代码省略.........
     matrix[2, 3] = "m";
     matrix[3][4] = "n";
     Console.WriteLine(matrix.ToString("E"));
     // check for items
     Console.WriteLine("Check for items ...");
     Console.WriteLine(matrix.ContainsAt(0, 1));
     Console.WriteLine(matrix.ContainsAt(1, 1));
     Console.WriteLine(matrix.Contains("c"));
     Console.WriteLine(matrix.Contains("C"));
     int rowIdx = -1, colIdx = -1;
     matrix.IndexOf("c", ref rowIdx, ref colIdx);
     Console.WriteLine("{0}, {1}", rowIdx, colIdx);
     // check for rows and columns
     Console.WriteLine("Check for rows and columns ...");
     Console.WriteLine(matrix.ContainsColAt(0));
     Console.WriteLine(matrix.ContainsColAt(100));
     Console.WriteLine(matrix.ContainsRowAt(0));
     Console.WriteLine(matrix.ContainsRowAt(100));
     // get first and last non-empty row and column index
     Console.WriteLine("Get first and last non-empty row and column index ...");
     Console.WriteLine(matrix.GetFirstNonEmptyRowIdx());
     Console.WriteLine(matrix.GetLastNonEmptyRowIdx());
     Console.WriteLine(matrix.GetFirstNonEmptyColIdx());
     Console.WriteLine(matrix.GetLastNonEmptyColIdx());
     // get first and last item in row
     Console.WriteLine("Get first and last item in row ...");
     Console.WriteLine(matrix[0].First);
     Console.WriteLine(matrix[3].Last);
     // create another SparseMatrix
     Console.WriteLine("Create another SparseMatrix ...");
     SparseMatrix<string> matrix2 = new SparseMatrix<string>();
     matrix2[0] = new SparseVector<string>(new IdxDat<string>[] {
         new IdxDat<string>(0, "A"),
         new IdxDat<string>(2, "B"),
         new IdxDat<string>(3, "C") });
     matrix2[2] = new SparseVector<string>(new IdxDat<string>[] {
         new IdxDat<string>(1, "D"),
         new IdxDat<string>(3, "E") });
     matrix2[3] = new SparseVector<string>(new IdxDat<string>[] {
         new IdxDat<string>(0, "G"),
         new IdxDat<string>(1, "H"),
         new IdxDat<string>(2, "I") });
     Console.WriteLine(matrix2.ToString("E"));
     // concatenate
     Console.WriteLine("Concatenate ...");
     matrix.AppendCols(matrix2, matrix.GetLastNonEmptyColIdx() + 1);
     Console.WriteLine(matrix.ToString("E"));
     // remove items
     Console.WriteLine("Remove items ...");
     matrix.RemoveAt(0, 1);
     matrix.RemoveAt(3, 5);
     Console.WriteLine(matrix.ToString("E"));
     // directly access to items
     Console.WriteLine("Directly access to items ...");
     int idx = matrix[0].GetDirectIdx(4);
     Console.WriteLine(idx);
     Console.WriteLine(matrix[0].GetDirect(idx));
     matrix[0].SetDirect(idx, "C");
     Console.WriteLine(matrix[1].GetDirect(0));
     matrix[1].RemoveDirect(0);
     Console.WriteLine(matrix.ToString("E"));
     // get properties
     Console.WriteLine("Get properties ...");
     Console.WriteLine("{0:0.00}%", matrix.GetSparseness(matrix.GetLastNonEmptyRowIdx() + 1, matrix.GetLastNonEmptyColIdx() + 1) * 100.0);
     Console.WriteLine(matrix.IsSymmetric());
     Console.WriteLine(matrix.ContainsDiagonalElement());
     Console.WriteLine(matrix.CountValues());
     // perform unary operation
     Console.WriteLine("Perform unary operation ...");
     matrix.PerformUnaryOperation(delegate(string item) { return item.ToUpper(); });
     Console.WriteLine(matrix.ToString("E"));
     // merge
     Console.WriteLine("Merge ...");
     matrix.Merge(matrix2, delegate(string a, string b) { return string.Format("{0}+{1}", a, b); });
     Console.WriteLine(matrix.ToString("E"));
     // clear row and column
     Console.WriteLine("Clear row and column ...");
     matrix.RemoveRowAt(2);
     matrix.RemoveColAt(1);
     Console.WriteLine(matrix.ToString("E"));
     // purge row and column
     Console.WriteLine("Purge row and column ...");
     matrix.PurgeRowAt(2);
     matrix.PurgeColAt(1);
     Console.WriteLine(matrix.ToString("E"));
     // get column copy
     Console.WriteLine("Get column copy ...");
     Console.WriteLine(matrix.GetColCopy(0));
     // transpose
     Console.WriteLine("Transpose ...");
     Console.WriteLine(matrix.GetTransposedCopy().ToString("E"));
     // set diagonal
     Console.WriteLine("Set diagonal ...");
     matrix.SetDiagonal(matrix.GetLastNonEmptyColIdx() + 1, "X");
     Console.WriteLine(matrix.ToString("E"));
     // make symmetric
     Console.WriteLine("Make symmetric ...");
     matrix.Symmetrize(delegate(string a, string b) { return string.Format("{0}+{1}", a, b); });
     Console.WriteLine(matrix.ToString("E"));
 }
开发者ID:viidea,项目名称:latino,代码行数:101,代码来源:Tutorial2_2.cs

示例5: TESTGetAllLaplaceMatrixInfo

        public void TESTGetAllLaplaceMatrixInfo(TriMesh mesh)
        {
            GenerateLaplaceMatrix(EnumLaplaceMatrix.Cot, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("Cot laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("Cot laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.CotNormalize, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("CotNormalize laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("CotNormalize laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.GraphTest, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("Graph laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("Graph laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.Mass, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("Mass laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("Mass laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.DualLaplace, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("Dual laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("Dual laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.MeanCurvature, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("MeanCurvature laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("MeanCurvature laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.MeanCurvatreNormalize, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("MeanCurvatreNormalize laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("MeanCurvatreNormalize laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.Rigid, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
            {
                Console.WriteLine("Rigid laplace is symmetric!");
            }
            else
            {
                Console.WriteLine("Rigid laplace is unsymmetric!");
            }

            CurrentMatrix = null;

            GenerateLaplaceMatrix(EnumLaplaceMatrix.Stffness, mesh);
            if (CurrentMatrix != null && CurrentMatrix.IsSymmetric())
//.........这里部分代码省略.........
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:101,代码来源:LaplaceManager.cs


注:本文中的SparseMatrix.IsSymmetric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。