private static void SetEntries(CoordinatesKeyedSparseMatrix <int> matrix, int x, int y, bool directed)
 {
     if (!directed)
     {
         throw new InvalidOperationException("Undirected edges are not supported.");
     }
     matrix.AddOrUpdate((y, y), 1, (k, v) => v + 1);
 }
Ejemplo n.º 2
0
 private static void SetEntries(CoordinatesKeyedSparseMatrix <int> matrix, int x, int y, int value, bool directed)
 {
     if (x == y)
     {
         throw new InvalidOperationException("Loops are not supported.");
     }
     if (directed)
     {
         throw new InvalidOperationException("Directed edges are not supported.");
     }
     matrix.TryAdd((x, y), value);
     matrix.TryAdd((y, x), value);
 }
        public (CoordinatesKeyedSparseMatrix <int>, List <int>, List <List <int> >, MatrixLinearIndexMode) TestMatrixToCVSCMOData()
        {
            CoordinatesKeyedSparseMatrix <int> sm = TestSparseMatrixData();
            List <int> v = new List <int> {
                1
            };
            List <List <int> > li = new List <List <int> >()
            {
                new List <int> {
                    4, 5, 11, 17, 23
                }
            };

            return(sm, v, li, MatrixLinearIndexMode.ColumnMajorOrder);
        }
        public (CoordinatesKeyedSparseMatrix <int>, List <int>, List <List <int> >, MatrixLinearIndexMode) TestMatrixToCVSRMOData()
        {
            CoordinatesKeyedSparseMatrix <int> sm = TestSparseMatrixData();
            List <int> v = new List <int> {
                1
            };
            List <List <int> > li = new List <List <int> >()
            {
                new List <int> {
                    1, 7, 13, 19, 20
                }
            };

            return(sm, v, li, MatrixLinearIndexMode.RowMajorOrder);
        }
        public (CoordinatesKeyedSparseMatrix <int>, List <int>, List <int>, List <int>) TestMatrixToCCSData()
        {
            CoordinatesKeyedSparseMatrix <int> sm = TestSparseMatrixData();
            List <int> v = new List <int> {
                1, 1, 1, 1, 1
            };
            List <int> cp = new List <int> {
                0, 1, 2, 3, 4, 5
            };
            List <int> ri = new List <int> {
                4, 0, 1, 2, 3
            };

            return(sm, v, cp, ri);
        }
        public (CoordinatesKeyedSparseMatrix <int>, List <int>, List <int>, List <int>) TestMatrixToCRSData()
        {
            CoordinatesKeyedSparseMatrix <int> sm = TestSparseMatrixData();
            List <int> v = new List <int> {
                1, 1, 1, 1, 1
            };
            List <int> rp = new List <int> {
                0, 1, 2, 3, 4, 5
            };
            List <int> ci = new List <int> {
                1, 2, 3, 4, 0
            };

            return(sm, v, rp, ci);
        }
        public static (CoordinatesKeyedSparseMatrix <int> sm, int[] v, int[] a) TestSparseMatrixVectorMultiplicationData()
        {
            CoordinatesKeyedSparseMatrix <int> sm = TestSparseMatrixData();

            int[] v = new int[] { 2, 0, 5, 0, 1 };
            int[] a = { 0, 5, 0, 1, 2 }; // expected product

            /*
             * 0 1 0 0 0   2   0
             * 0 0 1 0 0   0   5
             * 0 0 0 1 0 x 5 = 0
             * 0 0 0 0 1   0   1
             * 1 0 0 0 0   1   2
             */
            return(sm, v, a);
        }