コード例 #1
0
 public void Write(PartialMatrix <double> matrix, string fileName)
 {
     using (var writer = new StreamWriter(fileName))
     {
         Write(matrix, writer);
     }
 }
コード例 #2
0
        public PartialMatrix <double> ReadDouble(StreamReader reader)
        {
            double[][] elements = PartialMatrix <double> .CreateElements(_rowCount, _colCount);

            int row = 0;

            // Read the Body
            while (reader.EndOfStream == false)
            {
                string[] fields = reader.ReadLine().Split(new[] { _delimiter });

                if (fields.Length != _colCount)
                {
                    throw new InvalidDataException("Unexpected number of columns on line " + row);
                }

                for (int col = 0; col < fields.Length; col++)
                {
                    elements[row][col] = Convert.ToDouble(fields[col].Trim());
                }

                row++;
            }

            if (row != _rowCount)
            {
                throw new InvalidDataException("Unexpected number of rows in file");
            }

            return(new PartialMatrix <double>(_globalRowStartIndex, _globalRowStartIndex + _rowCount - 1,
                                              _globalColStartIndex, _globalColStartIndex + _colCount - 1, elements));
        }
コード例 #3
0
 public void Write(PartialMatrix <int> matrix, BinaryWriter writer)
 {
     for (int i = 0; i < matrix.RowCount; i++)
     {
         for (int j = 0; j < matrix.ColumnCount; j++)
         {
             writer.Write(matrix.Elements[i][j]);
         }
     }
 }
コード例 #4
0
 public void Write(PartialMatrix <double> matrix, string fileName)
 {
     using (Stream stream = File.Create(fileName))
     {
         using (var writer = new BinaryWriter(stream))
         {
             Write(matrix, writer);
         }
     }
 }
コード例 #5
0
        public PartialMatrix <double> ReadDouble(BinaryReader reader)
        {
            double[][] elements = PartialMatrix <double> .CreateElements(_rowCount, _colCount);

            for (int i = 0; i < _rowCount; i++)
            {
                for (int j = 0; j < _colCount; j++)
                {
                    elements[i][j] = reader.ReadDouble();
                }
            }

            return(new PartialMatrix <double>(_globalRowStartIndex, _globalRowStartIndex + _rowCount - 1,
                                              _globalColStartIndex, _globalColStartIndex + _colCount - 1, elements));
        }
コード例 #6
0
        public void Write(PartialMatrix <ushort> matrix, StreamWriter writer)
        {
            for (int i = 0; i < matrix.RowCount; i++)
            {
                for (int j = 0; j < matrix.ColumnCount; j++)
                {
                    if (j > 0)
                    {
                        writer.Write(_delimiter);
                    }

                    writer.Write(matrix.Elements[i][j].ToString());
                }

                writer.WriteLine();
            }
        }