market

package module
v0.0.0-...-ec99c48 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 9 Imported by: 0

README

matrix-market

Go Reference Build Status codecov Go Report Card

Installation

  go get -u github.com/wamuir/matrix-market

Usage

  var m market.COO

  file, err := os.Open("sparse.mtx")
  if err != nil {
      log.Fatal(err)
  }
  defer file.Close()

  _, err := m.UnmarshalTextFrom(file)
  if err != nil {
      log.Fatal(err)
  }

  var c *sparse.COO = m.ToCOO()  // github.com/james-bowman/sparse

Supported Formats

Sparse Matrices (Coordinate Format)

Sparse Real-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Coordinate Real General market.COO sparse.COO
Matrix Coordinate Real Skew-Symmetric market.COO sparse.COO
Matrix Coordinate Real Symmetric market.COO sparse.COO
Sparse Integer-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Coordinate Integer General market.COO sparse.COO
Matrix Coordinate Integer Skew-Symmetric market.COO sparse.COO
Matrix Coordinate Integer Symmetric market.COO sparse.COO
Sparse Complex-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Coordinate Complex General market.CDense mat.CDense
Matrix Coordinate Complex Hermitian market.CDense mat.CDense
Matrix Coordinate Complex Skew-Symmetric market.CDense mat.CDense
Matrix Coordinate Complex Symmetric market.CDense mat.CDense
Sparse Pattern Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Coordinate Pattern General market.COO sparse.COO
Matrix Coordinate Pattern Symmetric market.COO sparse.COO

Dense Matrices (Array Format)

Dense Real-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Array Real General market.Dense mat.Dense
Matrix Array Real Skew-Symmetric market.Dense mat.Dense
Matrix Array Real Symmetric market.Dense mat.Dense
Dense Integer-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Array Integer General market.Dense mat.Dense
Matrix Array Integer Skew-Symmetric market.Dense mat.Dense
Matrix Array Integer Symmetric market.Dense mat.Dense
Dense Complex-Valued Matrices
Object Format Field Symmetry Concrete Type Storage
Matrix Array Complex General market.CDense mat.CDense
Matrix Array Complex Hermitian market.CDense mat.CDense
Matrix Array Complex Skew-Symmetric market.CDense mat.CDense
Matrix Array Complex Symmetric market.CDense mat.CDense

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

Examples

Constants

This section is empty.

Variables

View Source
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 NewCDense

func NewCDense(d *mat.CDense) *CDense

NewCDense initializes a new CDense dense matrix from a mat.CDense matrix.

func (*CDense) Do

func (m *CDense) Do(fn func(i, j int, v complex128))

func (*CDense) MarshalText

func (m *CDense) MarshalText() ([]byte, error)

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

func (m *CDense) MarshalTextTo(w io.Writer) (int, error)

MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.

func (*CDense) ToCDense

func (m *CDense) ToCDense() *mat.CDense

ToCDense returns a mat.CDense matrix that shares underlying storage with the receiver.

func (*CDense) ToCMatrix

func (m *CDense) ToCMatrix() mat.CMatrix

ToCMatrix returns a mat.CMatrix complex matrix that shares underlying storage with the receiver.

func (*CDense) UnmarshalText

func (m *CDense) UnmarshalText(text []byte) error

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:

func (*CDense) UnmarshalTextFrom

func (m *CDense) UnmarshalTextFrom(r io.Reader) (int, error)

UnmarshalTextFrom deserializes r from Matrix Market format into the receiver.

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 NewCOO

func NewCOO(c *sparse.COO) *COO

NewCOO initializes a new COO sparse matrix from a sparse.COO matrix

func (*COO) Do

func (m *COO) Do(fn func(i, j int, v float64))

func (*COO) MarshalText

func (m *COO) MarshalText() ([]byte, error)

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

func (m *COO) MarshalTextTo(w io.Writer) (int, error)

MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.

func (*COO) ToCOO

func (m *COO) ToCOO() *sparse.COO

ToCOO returns a sparse.COO matrix that shared underlying storage with the receiver.

func (*COO) ToMatrix

func (m *COO) ToMatrix() mat.Matrix

ToMatrix returns a mat.Matrix real matrix that shared underlying storage with the receiver.

func (*COO) UnmarshalText

func (m *COO) UnmarshalText(text []byte) error

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⎦

func (*COO) UnmarshalTextFrom

func (m *COO) UnmarshalTextFrom(r io.Reader) (int, error)

UnmarshalTextFrom deserializes r from Matrix Market format into the receiver.

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 NewDense

func NewDense(d *mat.Dense) *Dense

NewDense initializes a new CDense dense matrix from a mat.Dense matrix.

func (*Dense) Do

func (m *Dense) Do(fn func(i, j int, v float64))

func (*Dense) MarshalText

func (m *Dense) MarshalText() ([]byte, error)

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

func (m *Dense) MarshalTextTo(w io.Writer) (int, error)

MarshalTextTo serializes the receiver to w in Matrix Market format and returns the result.

func (*Dense) ToDense

func (m *Dense) ToDense() *mat.Dense

ToDense returns a mat.Dense matrix that shares underlying storage with the receiver.

func (*Dense) ToMatrix

func (m *Dense) ToMatrix() mat.Matrix

ToMatrix returns a mat.Matrix complex matrix that shares underlying storage with the receiver.

func (*Dense) UnmarshalText

func (m *Dense) UnmarshalText(text []byte) error

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⎦

func (*Dense) UnmarshalTextFrom

func (m *Dense) UnmarshalTextFrom(r io.Reader) (int, error)

UnmarshalTextFrom deserializes r from Matrix Market format into the receiver.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL