Documentation ¶
Overview ¶
Package market reads and writes in the NIST Matrix Market native exchange format. The Matrix Market is a service of the Mathematical and Computational Sciences Division of the Information Technology Laboratory of the National Institute of Standards and Technology (NIST), containing "test data for use in comparative studies of algorithms for numerical linear algebra, featuring nearly 500 sparse matrices from a variety of applications, as well as matrix generation tools and services." The Matrix Market native exchange format has become a standard for exchanging matrix data.
Index ¶
- Variables
- type CDense
- func (m *CDense) Do(fn func(i, j int, v complex128))
- func (m *CDense) MarshalText() ([]byte, error)
- func (m *CDense) MarshalTextTo(w io.Writer) (int, error)
- func (m *CDense) ToCDense() *mat.CDense
- func (m *CDense) ToCMatrix() mat.CMatrix
- func (m *CDense) UnmarshalText(text []byte) error
- func (m *CDense) UnmarshalTextFrom(r io.Reader) (int, error)
- type COO
- func (m *COO) Do(fn func(i, j int, v float64))
- func (m *COO) MarshalText() ([]byte, error)
- func (m *COO) MarshalTextTo(w io.Writer) (int, error)
- func (m *COO) ToCOO() *sparse.COO
- func (m *COO) ToMatrix() mat.Matrix
- func (m *COO) UnmarshalText(text []byte) error
- func (m *COO) UnmarshalTextFrom(r io.Reader) (int, error)
- type Dense
- func (m *Dense) Do(fn func(i, j int, v float64))
- func (m *Dense) MarshalText() ([]byte, error)
- func (m *Dense) MarshalTextTo(w io.Writer) (int, error)
- func (m *Dense) ToDense() *mat.Dense
- func (m *Dense) ToMatrix() mat.Matrix
- func (m *Dense) UnmarshalText(text []byte) error
- func (m *Dense) UnmarshalTextFrom(r io.Reader) (int, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInputScanError = fmt.Errorf("error while scanning matrix input") ErrLineTooLong = fmt.Errorf("input line exceeds maximum length") ErrPrematureEOF = fmt.Errorf("required header items are missing") ErrNoHeader = fmt.Errorf("missing matrix market header line") ErrNotMTX = fmt.Errorf("input is not a matrix market file") ErrUnsupportedType = fmt.Errorf("unrecognizable matrix description") ErrUnwritable = fmt.Errorf("error writing matrix to io writer") )
Errors returned by failures to read a matrix
Functions ¶
This section is empty.
Types ¶
type CDense ¶
type CDense struct { Object string Format string Field string Symmetry string // contains filtered or unexported fields }
CDense is a type embedding of mat.CDense, for reading and writing complex-valued matrices in Matrix Market array format.
func (*CDense) Do ¶
func (m *CDense) Do(fn func(i, j int, v complex128))
func (*CDense) MarshalText ¶
MarshalText serializes the receiver to []byte in Matrix Market format and returns the result.
Example ¶
// mtx is a dense matrix representation with complex data mtx := mat.NewCDense(2, 2, []complex128{ complex(+0.944853346337906500, -0.154091238677780850), complex(-0.681501551465435000, +0.594570321595631100), complex(-0.658745773257358300, +0.897566664045815500), complex(+0.402696290353813800, +0.009438983689089353), }) // m is a CDense matrix initialized with mtx m := NewCDense(mtx) // serialize m into []byte (mm) mm, err := m.MarshalText() if err != nil { panic(err) } fmt.Println(string(mm))
Output: %%MatrixMarket matrix array complex general % 2 2 0.9448533463379065 -0.15409123867778085 -0.6587457732573583 0.8975666640458155 -0.681501551465435 0.5945703215956311 0.4026962903538138 0.009438983689089353
func (*CDense) MarshalTextTo ¶
MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.
func (*CDense) ToCDense ¶
ToCDense returns a mat.CDense matrix that shares underlying storage with the receiver.
func (*CDense) ToCMatrix ¶
ToCMatrix returns a mat.CMatrix complex matrix that shares underlying storage with the receiver.
func (*CDense) UnmarshalText ¶
UnmarshalText deserializes []byte from Matrix Market format into the receiver.
Example ¶
// mm is a complex-valued matrix in Matrix Market format mm := []byte( `%%MatrixMarket matrix array complex general 2 2 0.9448533463379065 -0.15409123867778085 -0.681501551465435 0.5945703215956311 -0.6587457732573583 0.8975666640458155 0.4026962903538138 0.009438983689089353`, ) // mtx is a dense matrix representation with complex data mtx := mat.NewCDense(2, 2, nil) // m is a CDense matrix initialized with mtx m := NewCDense(mtx) // deserialize mm into m err := m.UnmarshalText(mm) if err != nil { panic(err) }
Output:
type COO ¶
type COO struct { Object string Format string Field string Symmetry string // contains filtered or unexported fields }
COO is a type embedding of sparse.COO, for reading and writing real-valued matrices in Matrix Market coordinate format.
func (*COO) MarshalText ¶
MarshalText serializes the receiver to []byte in Matrix Market format and returns the result.
Example ¶
// mtx is a sparse matrix representation in coordinate format mtx := sparse.NewCOO(4, 5, nil, nil, nil) mtx.Set(0, 0, 0.944853346337906500) mtx.Set(1, 1, 0.897566664045815500) mtx.Set(2, 2, 0.402696290353813800) // m is a COO matrix initialized with mtx m := NewCOO(mtx) // serialized m into []byte (mm) mm, err := m.MarshalText() if err != nil { panic(err) } fmt.Println(string(mm))
Output: %%MatrixMarket matrix coordinate real general % 4 5 3 1 1 0.9448533463379065 2 2 0.8975666640458155 3 3 0.4026962903538138
func (*COO) MarshalTextTo ¶
MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.
func (*COO) ToCOO ¶
ToCOO returns a sparse.COO matrix that shared underlying storage with the receiver.
func (*COO) ToMatrix ¶
ToMatrix returns a mat.Matrix real matrix that shared underlying storage with the receiver.
func (*COO) UnmarshalText ¶
UnmarshalText deserializes []byte from Matrix Market format into the receiver.
Example ¶
// mm is a real-valued sparse matrix in Matrix Market coordinate format mm := []byte( `%%MatrixMarket matrix coordinate real general 3 3 3 1 1 0.9448533463379065 2 2 0.8975666640458155 3 3 0.4026962903538138`, ) // mtx is a coo matrix representation mtx := sparse.NewCOO(3, 3, nil, nil, nil) // m is a COO matrix initialized with mtx m := NewCOO(mtx) // deserialize mm into m err := m.UnmarshalText(mm) if err != nil { panic(err) } fmt.Printf("%v", mat.Formatted(m.ToMatrix()))
Output: ⎡0.9448533463379065 0 0⎤ ⎢ 0 0.8975666640458155 0⎥ ⎣ 0 0 0.4026962903538138⎦
type Dense ¶
type Dense struct { Object string Format string Field string Symmetry string // contains filtered or unexported fields }
Dense is a type embedding of mat.Dense, for reading and writing complex-valued matrices in Matrix Market array format.
func (*Dense) MarshalText ¶
MarshalText serializes the receiver to []byte in Matrix Market format and returns the result.
Example ¶
// mtx is a dense matrix representation mtx := mat.NewDense(4, 2, []float64{ +0.944853346337906500, -0.154091238677780850, -0.681501551465435000, +0.594570321595631100, -0.658745773257358300, +0.897566664045815500, +0.402696290353813800, +0.009438983689089353, }) // m is a Dense matrix initialized with mtx m := NewDense(mtx) // serialize m into []byte (mm) mm, err := m.MarshalText() if err != nil { panic(err) } fmt.Println(string(mm))
Output: %%MatrixMarket matrix array real general % 4 2 0.9448533463379065 -0.681501551465435 -0.6587457732573583 0.4026962903538138 -0.15409123867778085 0.5945703215956311 0.8975666640458155 0.009438983689089353
func (*Dense) MarshalTextTo ¶
MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.
func (*Dense) ToDense ¶
ToDense returns a mat.Dense matrix that shares underlying storage with the receiver.
func (*Dense) ToMatrix ¶
ToMatrix returns a mat.Matrix complex matrix that shares underlying storage with the receiver.
func (*Dense) UnmarshalText ¶
UnmarshalText deserializes []byte from Matrix Market format into the receiver.
Example ¶
// mm is a complex-valued matrix in Matrix Market format mm := []byte( `%%MatrixMarket matrix array real general 4 2 0.9448533463379065 -0.15409123867778085 -0.681501551465435 0.5945703215956311 -0.6587457732573583 0.8975666640458155 0.4026962903538138 0.009438983689089353`, ) // mtx is a dense matrix representation mtx := mat.NewDense(4, 2, nil) // m is a Dense matrix initialized with mtx m := NewDense(mtx) // deserialize mm into m err := m.UnmarshalText(mm) if err != nil { panic(err) } fmt.Printf("%v", mat.Formatted(m.ToMatrix()))
Output: ⎡ 0.9448533463379065 -0.6587457732573583⎤ ⎢-0.15409123867778085 0.8975666640458155⎥ ⎢ -0.681501551465435 0.4026962903538138⎥ ⎣ 0.5945703215956311 0.009438983689089353⎦