rewrite

package
v0.0.0-...-af045a5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnyExp

type AnyExp int

AnyExp represents any matrix expression. It is intended for use with the Template rewriter. It implements matrix algebra but if it is ever used for calculations it will cause a runtime panic. Note that this is an int so that it actually takes up memory - this is intentional. Go puts zero sized structs into the same address, which is no good if we want to compare their memory location to determine identity for wildcard matching.

func (*AnyExp) Add

Add two matrices together.

func (*AnyExp) At

func (m1 *AnyExp) At(r, c int) float64

At returns the value at a given row, column index.

func (*AnyExp) Copy

func (m1 *AnyExp) Copy() matrixexp.MatrixExp

Copy normally creates a (deep) copy of the Matrix Expression. However, to aid in rewriting expressions, Copy() of matrix expression wildcards is a nop.

func (*AnyExp) Dims

func (m1 *AnyExp) Dims() (r, c int)

Dims returns the matrix dimensions.

func (*AnyExp) DivElem

func (m1 *AnyExp) DivElem(m2 matrixexp.MatrixExp) matrixexp.MatrixExp

DivElem performs element-wise division.

func (*AnyExp) Err

func (m1 *AnyExp) Err() error

Err returns the first error encountered while constructing the matrix expression.

func (*AnyExp) Eval

func (m1 *AnyExp) Eval() matrixexp.MatrixLiteral

Eval returns a matrix literal.

func (*AnyExp) Match

func (m1 *AnyExp) Match(m2 matrixexp.MatrixExp) error

Match determines if a matrix expression wildcard matches another matrix expression.

func (*AnyExp) Mul

Mul performs matrix multiplication.

func (*AnyExp) MulElem

func (m1 *AnyExp) MulElem(m2 matrixexp.MatrixExp) matrixexp.MatrixExp

MulElem performs element-wise multiplication.

func (*AnyExp) Scale

func (m1 *AnyExp) Scale(c float64) matrixexp.MatrixExp

Scale performs scalar multiplication.

func (*AnyExp) String

func (m1 *AnyExp) String() string

String implements the Stringer interface.

func (*AnyExp) Sub

Sub subtracts the right matrix from the left matrix.

func (*AnyExp) T

func (m1 *AnyExp) T() matrixexp.MatrixExp

T transposes a matrix.

type Compiler

type Compiler interface {
	// Compile transforms a matrix, or returns an error indicating a problem
	// with either the matrix expression or the compiler.
	Compile(matrixexp.MatrixExp) (matrixexp.MatrixExp, error)

	// MustCompile is just like Compile, except that instead of returning an error
	// it will panic if it encounters a problem.  It is intended for use in init()
	MustCompile(matrixexp.MatrixExp) matrixexp.MatrixExp
}

A Compiler can transform matrix expressions by applying various optimizations to it, such as converting a.T().Mul(b.T()) to an appropriate call to DGEMM, or allowing concurrent evaluation of (a.Mul(b)).Add(c.Mul(d)) via Async.

type ExpMismatch

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

ExpMismatch indicates that an expression does not match an expected pattern.

func (*ExpMismatch) Error

func (e *ExpMismatch) Error() string

Error implements the error interface.

type Matcher

type Matcher interface {
	Match(matrixexp.MatrixExp) error
}

A Matcher can determine if an expression wildcard matches another matrix expression. If the expression does not match the wildcard then it returns an error explaining why.

type NewExpMismatch

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

NewExpMismatch indicates that a wildcard was expected to be repeated in the expression tree, but a new matrix expressio was found. For example, the expression A.Mul(A.T()) would return this when compared with B.Mul(C.T())

func (*NewExpMismatch) Error

func (e *NewExpMismatch) Error() string

Error implements the error interface.

type Rewriter

type Rewriter interface {
	Rewrite(matrixexp.MatrixExp) (matrixexp.MatrixExp, error)
}

Rewriter can convert one matrix expression to another.

func Template

func Template(from, to matrixexp.MatrixExp) Rewriter

Template produces a rewrite rule from a matrix expression template.

Jump to

Keyboard shortcuts

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