tensor

package
v0.0.0-...-32ffa8f Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2017 License: GPL-3.0 Imports: 7 Imported by: 0

README

Tensor

Tensor is a multi-dimensional tensor used in the neural network library Weight.

The underlying data is a slice of float64 and the shape is a slice of ints, one for each dimension.

Example usage:

//We can create a tensor manually
t1 := Tensor{
  Values: []float64{
    0, 0, 0,
    1, 0.5, 1,
    0, 1, 0},
  Size: []int{3, 3},
}

//We can also use NewTensor. It creates a tensor with a given size and allocates the Values slice with the required size
t2 := tensor.NewTensor(2,2,1)
//Now we can use any value within the shape of the tensor. This sets the value 0.5 to the position (1,0,0)
t2.SetVal(0.5, 1,0,0)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SizeLength

func SizeLength(size []int) int

Utils

Types

type Stats

type Stats struct {
	Mean  float64
	StDev float64
	Min   float64
	Max   float64
}

type Tensor

type Tensor struct {
	Values []float64
	Size   []int //Size of each dimension in order. Values should be bigger than 0
	// contains filtered or unexported fields
}

Tensor is a structure to represent a multiple dimension matrix

func NewTensor

func NewTensor(size ...int) *Tensor

func Unmarshal

func Unmarshal(r io.Reader) (*Tensor, error)

func (*Tensor) Add

func (t *Tensor) Add(a ...*Tensor) error

func (*Tensor) AddVal

func (t *Tensor) AddVal(val float64, index ...int)

AddVal increases the value at index by val

func (*Tensor) Allocate

func (t *Tensor) Allocate(size ...int) error

SetSize sets the size of Tensor and allocates the necessary memory

func (*Tensor) Copy

func (t *Tensor) Copy() *Tensor

Copy the values into a new Tensor struct

func (*Tensor) DimToFlat

func (t *Tensor) DimToFlat(index ...int) int
DiToFlat returns the position in the Values slice of a value in the position given by the index.

For example in a 2x2 tensor, DimToFlat(0,0) will return 0 and DimToFlat(0,1) will return 2

func (*Tensor) FlatToDim

func (t *Tensor) FlatToDim(index int) []int

func (*Tensor) GetDims

func (t *Tensor) GetDims() int

GetDims returns the number of dimensions

func (*Tensor) GetNumberOfValues

func (t *Tensor) GetNumberOfValues() int

func (*Tensor) GetVal

func (t *Tensor) GetVal(index ...int) float64

GetVal return the value at the index

func (*Tensor) HasSize

func (t *Tensor) HasSize(size []int) bool

func (*Tensor) Image

func (t *Tensor) Image(dynamicRange float64) (image.Image, error)

func (*Tensor) ImageSlice

func (t *Tensor) ImageSlice() ([]image.Image, error)

func (*Tensor) InBounds

func (t *Tensor) InBounds(index ...int) bool

func (*Tensor) Marshal

func (t *Tensor) Marshal(w io.Writer) error

func (*Tensor) Max

func (t *Tensor) Max() (int, float64)

func (*Tensor) MaxAbs

func (t *Tensor) MaxAbs() (int, float64)

func (*Tensor) Mean

func (t *Tensor) Mean() float64

func (*Tensor) Min

func (t *Tensor) Min() (int, float64)

func (*Tensor) Mul

func (t *Tensor) Mul(s float64)

func (*Tensor) SetVal

func (t *Tensor) SetVal(val float64, index ...int)

SetVal sets the value at index to val

func (*Tensor) Slice

func (t *Tensor) Slice(indexes ...int) *Tensor

func (*Tensor) Stats

func (t *Tensor) Stats() *Stats

Stats returns all the statistics about the values in the tensor. It is just a convinient method if you need them all

func (*Tensor) StdDev

func (t *Tensor) StdDev() float64

func (*Tensor) Substract

func (t *Tensor) Substract(s *Tensor) error

func (*Tensor) Zero

func (t *Tensor) Zero(val float64)

Zero sets all values to val

Jump to

Keyboard shortcuts

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