Ejemplo n.º 1
0
        public static double[,] ReadSampleMatrix(StreamReader reader, MatrixSize mtxSize)
        {
            var mtx      = new double[mtxSize.Rows, mtxSize.Colums];
            int rowIndex = 0;

            while (rowIndex < mtxSize.Rows && !reader.EndOfStream)
            {
                string line = reader.ReadLine();
                line = line.Trim(SpacesChars);
                if (line.Length == 0)
                {
                    continue;
                }

                double[] currRow = ReadMatrixRowDouble(line);
                if (currRow.Length != mtxSize.Colums)
                {
                    throw new FormatException($"Expected matrix columns count: {mtxSize.Colums}, given: {currRow.Length}");
                }

                for (int col = 0; col < currRow.Length; ++col)
                {
                    mtx[rowIndex, col] = currRow[col];
                }

                rowIndex++;
            }

            if (rowIndex != mtxSize.Rows)
            {
                throw new FormatException($"Expected matrix rows count: {mtxSize.Rows}, given: {rowIndex}");
            }

            return(mtx);
        }
Ejemplo n.º 2
0
        public static List <Sample> LoadSamples(string filename)
        {
            var samples = new List <Sample>();

            using (var reader = new StreamReader(filename))
            {
                MatrixSize matrixSize = ReadMatrixSize(reader.ReadLine());
                while (!reader.EndOfStream)
                {
                    samples.Add(new Sample(ReadSampleTitle(reader), ReadSampleMatrix(reader, matrixSize)));
                }
            }

            if (samples.Count == 0)
            {
                throw new FormatException("At least one sample needed");
            }

            return(samples);
        }