Пример #1
0
        //Operators
        public static SparseVector operator +(SparseVector v1, SparseVector v2)
        {
            SparseVector sum = new SparseVector();

            //SortedDictionary<int, double>.KeyCollection keys1 = v1.getKeys();
            //SortedDictionary<int, double>.KeyCollection keys2 = v2.getKeys();

            if (v1 != null)
            {
                if (v2 != null)
                {
                    foreach (int ID in v1.vector.Keys)
                    {
                        if (v2.ContainsKey(ID))
                        {
                            sum[ID] = v1[ID] + v2[ID];
                        }
                        else
                        {
                            sum[ID] = v1[ID];
                        }
                    }
                }
                else
                {
                    sum.copy(v1);
                }
            }
            if (v2 != null)
            {
                if (v1 != null)
                {
                    foreach (int ID in v2.vector.Keys)
                    {
                        if (!v1.ContainsKey(ID))
                        {
                            sum[ID] = v2[ID];
                        }
                    }
                }
                else
                {
                    sum.copy(v2);
                }
            }

            return(sum);
        }
Пример #2
0
 public void copy(SparseMatrix sm)
 {
     matrix.Clear();
     foreach (KeyValuePair <int, SparseVector> kvp in sm.matrix)
     {
         SparseVector vec = new SparseVector();
         vec.copy(kvp.Value);
         matrix.Add(kvp.Key, vec);
     }
 }
Пример #3
0
 public void copy(SparseMatrix sm)
 {
     matrix.Clear();
     foreach (KeyValuePair<int, SparseVector> kvp in sm.matrix)
     {
         SparseVector vec = new SparseVector();
         vec.copy(kvp.Value);
         matrix.Add(kvp.Key, vec);
     }
 }
Пример #4
0
        //Operators
        public static SparseVector operator +(SparseVector v1, SparseVector v2)
        {
            SparseVector sum = new SparseVector();
            //SortedDictionary<int, double>.KeyCollection keys1 = v1.getKeys();
            //SortedDictionary<int, double>.KeyCollection keys2 = v2.getKeys();

            if (v1 != null)
            {
                if (v2 != null)
                {
                    foreach (int ID in v1.vector.Keys)
                    {
                        if (v2.ContainsKey(ID))
                        {
                            sum[ID] = v1[ID] + v2[ID];
                        }
                        else
                            sum[ID] = v1[ID];
                    }
                }
                else
                {
                    sum.copy(v1);
                }
            }
            if (v2 != null)
            {
                if (v1 != null)
                {
                    foreach (int ID in v2.vector.Keys)
                    {
                        if (!v1.ContainsKey(ID))
                            sum[ID] = v2[ID];
                    }
                }
                else
                {
                    sum.copy(v2);
                }
            }

            return sum;
        }