matrix

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package matrix provides basic matrix operations.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidDim     = errors.New("matrix: invalid dimension")
	ErrInvalidMatrix  = errors.New("matrix: invalid matrix")
	ErrSingularMatrix = errors.New("matrix: singular matrix")
)

Errors.

Functions

This section is empty.

Types

type Matrix

type Matrix struct {
	// contains filtered or unexported fields
}

Matrix represents a matrix.

Example
package main

import (
	"fmt"
	"log"

	"gitee.com/ofunc/matrix"
)

func main() {
	const filename = "example.out"
	// Create random matrix.
	a := matrix.Rand(8, 8)
	b := matrix.Rand(8, 8)

	// Do mul operation.
	c := a.Mul(b)

	// DumpFile dumps the matrix to file.
	if err := c.DumpFile(filename); err != nil {
		log.Fatal(err)
	}

	// LoadFile loads the matrix from file.
	d, err := matrix.LoadFile(filename)
	if err != nil {
		log.Fatal(err)
	}

	// Print the matrix.
	fmt.Println(d)
}
Output:

func Diag

func Diag(es ...float64) *Matrix

Diag creates a diagonal matrix.

func Eye

func Eye(m, n int) *Matrix

Eye creates a eye matrix.

func Load

func Load(r io.Reader) (a *Matrix, err error)

Load loads a matrix from io.Reader.

func LoadFile

func LoadFile(name string) (*Matrix, error)

LoadFile loads a matrix from file.

func NormRand

func NormRand(m, n int) *Matrix

NormRand creates a normally random matrix.

func Ones

func Ones(m, n int) *Matrix

Ones creates a ones matrix.

func Rand

func Rand(m, n int) *Matrix

Rand creates a random matrix.

func Vector

func Vector(es ...float64) *Matrix

Vector creates a vector.

func Zeros

func Zeros(m, n int) *Matrix

Zeros creates a zeros matrix.

func (*Matrix) Add

func (a *Matrix) Add(b *Matrix) *Matrix

Add dones the add operation.

func (*Matrix) Copy

func (a *Matrix) Copy() *Matrix

Copy makes a copy of the matrix.

func (*Matrix) Det

func (a *Matrix) Det() float64

Det returns the determinant.

func (*Matrix) Dim

func (a *Matrix) Dim() (int, int)

Dim returns the matrix dimension.

func (*Matrix) Div

func (a *Matrix) Div(b *Matrix) *Matrix

Div dones the div operation.

func (*Matrix) Dump added in v0.0.3

func (a *Matrix) Dump(w io.Writer) error

Dump dumps a matrix to io.Writer.

func (*Matrix) DumpFile added in v0.0.3

func (a *Matrix) DumpFile(name string) error

DumpFile dumps a matrix to file.

func (*Matrix) Get

func (a *Matrix) Get(i, j int) float64

Get gets the element by index.

func (*Matrix) Inv

func (a *Matrix) Inv() *Matrix

Inv returns the inverse matrix.

func (*Matrix) Mul

func (a *Matrix) Mul(b *Matrix) *Matrix

Mul dones the mul operation.

func (*Matrix) Scale

func (a *Matrix) Scale(s float64) *Matrix

Scale returns the scaled matrix.

func (*Matrix) Set

func (a *Matrix) Set(i, j int, e float64) *Matrix

Set sets the element by index.

func (*Matrix) String

func (a *Matrix) String() string

String returns the matrix as string.

func (*Matrix) Sub

func (a *Matrix) Sub(b *Matrix) *Matrix

Sub dones the sub operation.

func (*Matrix) Tran

func (a *Matrix) Tran() *Matrix

Tran returns the transposed matrix.

Jump to

Keyboard shortcuts

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