Exemplo n.º 1
0
        public Task BinarySaveAsync <T>(Matrix <T> matrix) where T : unmanaged
        {
            using var stream          = new FileStream(PathBin, FileMode.OpenOrCreate);
            using BinaryWriter writer = new BinaryWriter(stream);
            var writeFunc = BinaryWriteExtensions <T> .GetWriteFunc();

            var array = matrix.GetArray();

            writer.Write(matrix.Rows);
            writer.Write(matrix.Columns);
            for (int i = 0; i < array.Length; i++)
            {
                writeFunc(writer, array[i]);
            }

            return(Task.CompletedTask);
        }
Exemplo n.º 2
0
        public Task <Matrix <T> > BinaryOpenAsync <T>() where T : unmanaged
        {
            if (!File.Exists(PathBin))
            {
                throw new MatrixDotNetException($"File not found: \"{PathBin}\"");
            }

            using var stream = new FileStream(PathBin, FileMode.Open);

            using var reader = new BinaryReader(stream);

            int rows    = reader.ReadInt32();
            int columns = reader.ReadInt32();

            var array = new T[rows * columns];

            for (int i = 0; i < array.Length; i++)
            {
                array[i] = BinaryWriteExtensions <T> .Read(reader);
            }
            var matrix = new Matrix <T>(array, rows, columns);

            return(Task.FromResult(matrix));
        }