mat

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2019 License: MIT Imports: 5 Imported by: 0

README

mat

this is a simple go wrapper on TensorFlow api for working with matrix data.

installation

install Go API for TensorFlow https://www.tensorflow.org/install/lang_go

$ go get github.com/sdeoras/comp/...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mat

type Mat struct {
	Buf  []float64
	Size []int64
}

func (*Mat) GetRaw

func (m *Mat) GetRaw() []float64

GetRaw returns raw buffer of the matrix

func (*Mat) GetSize

func (m *Mat) GetSize() []int

GetSize returns the size of matrix.

func (*Mat) IsEqual

func (m *Mat) IsEqual(x *Mat) bool

IsEqual compares two matrices for their content and size and only returns true if both checks are true.

func (*Mat) IsSameSize

func (m *Mat) IsSameSize(x *Mat) bool

IsSameSize compares two matrices for their size.

func (*Mat) Numel

func (m *Mat) Numel() int64

Numel computes number of elements in matrix.

type Matrix

type Matrix interface {
	// Numel computes number of elements in matrix.
	Numel() int64
	// GetSize returns the size of matrix.
	GetSize() []int
	// GetRaw returns raw buffer of the matrix
	GetRaw() []float64
	// IsEqual compares two matrices for their content and size and only returns true
	// if both checks are true.
	IsEqual(x *Mat) bool
	// IsSameSize compares two matrices for their size.
	IsSameSize(x *Mat) bool
}

Matrix is an interface defining following methods.

type Op

type Op struct {
	// It embeds common op
	common.Op
}

Op is the operator for TF interface.

func NewOperator

func NewOperator(options *tf.SessionOptions) (*Op, error)

NewOperator provides an instance of new operator for cloud file I/O

func (*Op) Inv

func (op *Op) Inv(mat *Mat) (*Mat, error)

Inv inverts a matrix assuming it is invertible.

func (*Op) Mul

func (op *Op) Mul(x, y *Mat) (*Mat, error)

Mul multiples two matrices.

func (*Op) New

func (op *Op) New(buf []float64, size ...int) (*Mat, error)

New creates a new matrix from a given slice.

func (*Op) Ones

func (op *Op) Ones(size ...int) (*Mat, error)

Ones is a matrix with all ones.

func (*Op) Print

func (op *Op) Print(w io.Writer, mat *Mat) error

func (*Op) Qr added in v0.1.2

func (op *Op) Qr(mat *Mat) (*Mat, *Mat, error)

Qr takes QR decomposition of a matrix.

func (*Op) Rand

func (op *Op) Rand(size ...int) (*Mat, error)

Rand is a matrix with random numbers that have uniform distribution.

func (*Op) Randn

func (op *Op) Randn(size ...int) (*Mat, error)

Randn is a matrix with random numbers that have normal distribution.

func (*Op) Repmat

func (op *Op) Repmat(mat *Mat, dim ...int) (*Mat, error)

Repmat repeats input matrix multiple times as specified in dim array

func (*Op) Reshape

func (op *Op) Reshape(mat *Mat, size ...int) (*Mat, error)

Reshape reshapes the input matrix with new size.

func (*Op) Slice

func (op *Op) Slice(mat *Mat, begin []int, size ...int) (*Mat, error)

Slice inverts a matrix assuming it is invertible.

func (*Op) Transpose added in v0.1.2

func (op *Op) Transpose(mat *Mat) (*Mat, error)

Transpose takes transpose of a matrix. Defined only for a 2D matrix.

func (*Op) Zeros

func (op *Op) Zeros(size ...int) (*Mat, error)

Zeros is a matrix with all zeros.

type Operator

type Operator interface {
	io.Closer

	// New matrix from buffer.
	New(buf []float64, size ...int) (*Mat, error)
	// Zeros is a new matrix with all zeros.
	Zeros(size ...int) (*Mat, error)
	// Ones is a new matrix with all ones.
	Ones(size ...int) (*Mat, error)
	// Rand is a new matrix with random numbers with uniform distribution.
	Rand(size ...int) (*Mat, error)
	// Randn is a new matrix with random numbers with normal distribution.
	Randn(size ...int) (*Mat, error)

	// Reshape reshapes a given matrix to new size.
	Reshape(mat *Mat, size ...int) (*Mat, error)
	// Slice can extract a slice from a matrix.
	Slice(mat *Mat, begin []int, size ...int) (*Mat, error)
	// Transpose takes transpose of a matrix. Defined only for a 2D matrix.
	Transpose(mat *Mat) (*Mat, error)
	// Repmat repeats a matrix as many times along dimensions as requested.
	Repmat(mat *Mat, dim ...int) (*Mat, error)

	// Mul multiples two matrices.
	Mul(x, y *Mat) (*Mat, error)
	// Inv takes inverse of a matrix.
	Inv(mat *Mat) (*Mat, error)
	// Qr takes QR decomposition of a matrix.
	Qr(mat *Mat) (*Mat, *Mat, error)

	// Print will pretty print input matrix.
	Print(w io.Writer, mat *Mat) error
}

Operator is the matrix operator that works on a session which needs to be closed.

Jump to

Keyboard shortcuts

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