Exemple #1
0
        public override bool Equals(object obj)
        {
            SparseMatrixOld sm = obj as SparseMatrixOld;

            if (sm != null)
            {
                if (this.ItemCount != sm.ItemCount ||
                    this.RowCount != sm.RowCount ||
                    this.ColCount != sm.ColCount
                    )
                {
                    return(false);
                }
                var list = this.MatrixItems;
                list.Sort();
                var list2 = sm.MatrixItems;
                list2.Sort();
                int i = 0;
                foreach (var item in this.MatrixItems)
                {
                    if (!list[i].Equals(list2[i]))
                    {
                        return(false);
                    }
                    i++;
                }
            }
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// 从二进制文件中读取。
        ///  格式定义:1. 前3个为int,分别指行、列和集合数量;2.后面子项集合,分别为行(int)列(int)标号和双精度值。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static SparseMatrixOld FromBinary(string path)
        {
            SparseMatrixOld matr = null;

            using (BinaryReader br = new BinaryReader(new FileStream(path, FileMode.Open, FileAccess.Read)))
            {
                int RowCount = br.ReadInt32();
                int ColCount = br.ReadInt32();
                matr = new SparseMatrixOld(RowCount, ColCount);
                int itemCount = br.ReadInt32();
                for (int i = 0; i < itemCount; i++)
                {
                    //各个节点位置无关,可以考虑并行存取,但是由于内存共享,还得序列化读取。
                    MatrixItem item = new MatrixItem()
                    {
                        Row = br.ReadInt32(), Col = br.ReadInt32(), Value = br.ReadDouble()
                    };
                    matr.MatrixItems.Add(item);
                }

                return(matr);
            }
        }