Documentation
¶
Overview ¶
Package mtx reads and writes the Matrix Market exchange format (https://math.nist.gov/MatrixMarket/formats.html): coordinate and array layouts; real, integer, pattern and complex fields; general, symmetric, skew-symmetric and hermitian symmetry. Gzip-compressed input is detected by its magic bytes. Equivalents: scipy.io.mmread / mmwrite, MATLAB's mmread.m.
Index ¶
Constants ¶
const ( Coordinate Layout = "coordinate" Array Layout = "array" Real Field = "real" Integer Field = "integer" Pattern Field = "pattern" Complex Field = "complex" General Symmetry = "general" Symmetric Symmetry = "symmetric" SkewSymmetric Symmetry = "skew-symmetric" Hermitian Symmetry = "hermitian" )
Constants naming the Matrix Market vocabulary.
Variables ¶
var DefaultLimits = Limits{MaxDim: 1 << 27, MaxEntries: 1 << 28, MaxLine: 1 << 16, MaxBytes: 1 << 34, MaxComments: 1 << 12}
DefaultLimits are generous for real matrices (2.7e8 entries) and refuse absurd headers.
var ErrFormat = errors.New("mtx: malformed file")
ErrFormat reports a malformed Matrix Market file.
Functions ¶
Types ¶
type Header ¶
type Header struct {
Layout Layout
Field Field
Symmetry Symmetry
Rows int
Cols int
Entries int // stored entries (coordinate) or stored values (array)
Comments []string
}
Header is the information of the banner and size lines.
type Limits ¶
type Limits struct {
MaxDim int // rows and columns
MaxEntries int // declared coordinate entries; rows*cols of an array file
MaxLine int // bytes in one line
MaxBytes int64 // bytes read (after decompression)
MaxComments int // comment lines kept in Header.Comments
}
Limits bound what Read accepts from an untrusted stream. A zero field takes its DefaultLimits value. Nothing is allocated from a declared size before the data that backs it has been read, but the Matrix is later converted with O(Rows+Cols) arrays, hence MaxDim.
type Matrix ¶
Matrix is a file read by Read. Exactly one of Real and Complex is set: Complex for the complex field, Real otherwise (pattern entries are 1). Symmetry is expanded: the COO matrices hold the full matrix, and Header.Symmetry records what the file declared.
func ReadLimited ¶
ReadLimited parses a Matrix Market stream, refusing input beyond lim.
func (*Matrix) ComplexCSR ¶
func (m *Matrix) ComplexCSR() *sparse.CSR[complex128]
ComplexCSR returns the matrix as a complex CSR matrix (real files are widened).
type Options ¶
type Options struct {
Layout Layout // Coordinate (default) or Array
Field Field // default: real for float64 data, complex for complex128
Symmetry Symmetry // default General; others write only the lower triangle
Comments []string
}
Options controls Write. The zero value writes a general coordinate file whose field is real (float64) or complex (complex128).