/// <summary> /// Reads the named matrices from the file or stream. /// </summary> /// <param name="names">The names of the matrices to retrieve.</param> /// <returns> /// The named matrices from the file or stream. The key to the <see cref="IDictionary{T,K}"/> /// is the matrix's name.</returns> public IDictionary <string, Matrix <TDataType> > ReadMatrices(IEnumerable <string> names) { Stream stream; if (_filename == null) { stream = _stream; _stream.Seek(0, SeekOrigin.Begin); } else { stream = new BufferedStream(new FileStream(_filename, FileMode.Open, FileAccess.Read)); } var parser = new MatlabParser <TDataType>(stream, names); var file = parser.Parse(); if (_filename != null) { stream.Close(); stream.Dispose(); } return(file.Matrices.ToDictionary(matrix => matrix.Key, matrix => matrix.Value)); }
/// <summary> /// Reads the named matrix from the file or stream. /// </summary> /// <param name="matrixName">The name of the matrix to read.</param> /// <returns> /// A sparse or dense matrix depending on how the matrix /// is defined in the Matlab file. /// <see langword="null"/> is returned if a matrix with the requests name doesn't exist. /// </returns> public Matrix <TDataType> ReadMatrix(string matrixName) { Stream stream; if (_filename == null) { stream = _stream; _stream.Seek(0, SeekOrigin.Begin); } else { stream = new FileStream(_filename, FileMode.Open, FileAccess.Read); } var names = string.IsNullOrEmpty(matrixName) ? new string[] { } : new[] { matrixName }; var parser = new MatlabParser <TDataType>(stream, names); var file = parser.Parse(); Matrix <TDataType> matrix = null; if (string.IsNullOrEmpty(matrixName)) { matrix = file.FirstMatrix; } else if (file.Matrices.ContainsKey(matrixName)) { matrix = file.Matrices[matrixName]; } if (_filename != null) { stream.Close(); stream.Dispose(); } return(matrix); }
/// <summary> /// Reads the named matrix from the file or stream. /// </summary> /// <param name="matrixName">The name of the matrix to read.</param> /// <returns> /// If the matrix is stored as a sparse matrix, then a <see cref="SparseMatrix"/> is returned. Otherwise, a <see cref="DenseMatrix"/> /// is returned. <see langword="null"/> is returned if a matrix with the requests name doesn't exist. /// </returns> public Matrix<float> ReadMatrix(string matrixName) { Stream stream; if (_filename == null) { stream = _stream; _stream.Seek(0, SeekOrigin.Begin); } else { stream = new FileStream(_filename, FileMode.Open, FileAccess.Read); } var names = string.IsNullOrEmpty(matrixName) ? new string[] { } : new[] { matrixName }; var parser = new MatlabParser(stream, names); var file = parser.Parse(); Matrix<float> matrix = null; if (string.IsNullOrEmpty(matrixName)) { matrix = file.FirstMatrix; } else if (file.Matrices.ContainsKey(matrixName)) { matrix = file.Matrices[matrixName]; } if (_filename != null) { stream.Close(); stream.Dispose(); } return matrix; }
/// <summary> /// Reads the named matrices from the file or stream. /// </summary> /// <param name="names">The names of the matrices to retrieve.</param> /// <returns> /// The named matrices from the file or stream. /// </returns> public Matrix<float>[] ReadMatrices(IEnumerable<string> names) { Stream stream; if (_filename == null) { stream = _stream; _stream.Seek(0, SeekOrigin.Begin); } else { stream = new BufferedStream(new FileStream(_filename, FileMode.Open, FileAccess.Read)); } var parser = new MatlabParser(stream, names); var file = parser.Parse(); var matrices = new Matrix<float>[file.Matrices.Count]; var i = 0; foreach (var matrix in file.Matrices.Values) { matrices[i++] = matrix; } if (_filename != null) { stream.Close(); stream.Dispose(); } return matrices; }