dense

package
v0.0.0-...-225e849 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2020 License: Apache-2.0 Imports: 5 Imported by: 8

README

Dense

Dense provides extension methods to a Dense tensor found in gorgonia's tensor package

Documentation

Overview

Package dense provides methods for Gorgonia's Dense Tensors.

Index

Constants

View Source
const FauxZero = 1e-6

FauxZero is the faux zero value used to prevent divde by zero errors.

Variables

This section is empty.

Functions

func AMax

func AMax(d *tensor.Dense, axis int) (interface{}, error)

AMax returns the maximum value in a tensor along an axis. TODO: support returning slice.

func AMaxF32

func AMaxF32(d *tensor.Dense, axis int) (float32, error)

AMaxF32 returns the maximum value in a tensor along an axis as a float32.

func BroadcastAdd

func BroadcastAdd(a, b *tensor.Dense) (retVal *tensor.Dense, err error)

BroadcastAdd adds 'a' to 'b' element-wise using broadcasting rules.

Shapes are compared element-wise starting with trailing dimensions and working its way forward. Dimensions are compatible if: - they are equal - one of them is 1

func BroadcastDiv

func BroadcastDiv(a, b *tensor.Dense) (retVal *tensor.Dense, err error)

BroadcastDiv safely divides 'a' to 'b' element-wise using broadcasting rules. Any zero values in 'b' will be slightly augmented.

Shapes are compared element-wise starting with trailing dimensions and working its way forward. Dimensions are compatible if: - they are equal - one of them is 1

func BroadcastMul

func BroadcastMul(a, b *tensor.Dense) (retVal *tensor.Dense, err error)

BroadcastMul multiplies 'a' to 'b' element-wise using broadcasting rules.

Shapes are compared element-wise starting with trailing dimensions and working its way forward. Dimensions are compatible if: - they are equal - one of them is 1

func BroadcastSub

func BroadcastSub(a, b *tensor.Dense) (retVal *tensor.Dense, err error)

BroadcastSub subtracts 'a' from 'b' element-wise using broadcasting rules.

Shapes are compared element-wise starting with trailing dimensions and working its way forward. Dimensions are compatible if: - they are equal - one of them is 1

func Concat

func Concat(axis int, tensors ...*t.Dense) (retVal *t.Dense, err error)

Concat a list of tensors along a given axis.

func ConcatOr

func ConcatOr(axis int, a, b *t.Dense) (retVal *t.Dense, err error)

ConcatOr return b if a is nil.

func Contains

func Contains(d *t.Dense, val interface{}) (contains bool, indicies []int)

Contains checks if a tensor contains a value.

func Div

func Div(a, b *t.Dense) (*t.Dense, error)

Div safely divides 'a' by 'b' by slightly augmenting any zero values in 'b'.

func ExpandDims

func ExpandDims(t *tensor.Dense, axis int) error

ExpandDims expands the dimensions of a tensor along the given axis.

func ExpandDimsShape

func ExpandDimsShape(shape tensor.Shape, axis int) tensor.Shape

ExpandDimsShape expands the dimensions of a shape along the given axis.

func FauxZeroValue

func FauxZeroValue(dt t.Dtype) interface{}

FauxZeroValue is a faux zero value for the given datatype.

func Fill

func Fill(val interface{}, shape ...int) *t.Dense

Fill creates a tensor and fills it with the given value.

func ManyOfOne

func ManyOfOne(t *tensor.Dense) error

ManyOfOne ensures the given tensor ends with a shape of 1.

func Mean

func Mean(x *t.Dense, along ...int) (*t.Dense, error)

Mean of the tensor along the axis.

y=Σx/n

func MinMaxNorm

func MinMaxNorm(x, min, max *t.Dense) (*t.Dense, error)

MinMaxNorm normalizes the input x using pointwise min-max normalization along the axis. This is a pointwise operation and requires the shape of the min/max tensors be equal to x.

y=(x-min)/(max-min)

func MulShape

func MulShape(shape tensor.Shape, by int) tensor.Shape

MulShape multiplies shape elementwise by the given int.

func Neg

func Neg(v *tensor.Dense) (*t.Dense, error)

Neg negates the tensor elementwise.

func NegValue

func NegValue(dt t.Dtype) interface{}

NegValue for the given datatype.

func NormalizeZeros

func NormalizeZeros(d *t.Dense) error

NormalizeZeros normalizes the zero values.

func OneHotVector

func OneHotVector(id, classes int, dt t.Dtype) (retVal *t.Dense, err error)

OneHotVector creates a one hot vector for the given id within the number of classses.

Note: this is mostly taken from gorgonia core, but was needed as a basic tensor function, should be contributed back upstream.

func OneOfMany

func OneOfMany(t *tensor.Dense) error

OneOfMany ensures the given tensor starts with a shape of 1.

func RandN

func RandN(dt t.Dtype, shape ...int) *t.Dense

RandN generates a new dense tensor of the given shape with values populated from the standard normal distribution.

func Repeat

func Repeat(t *tensor.Dense, axis int, repeats ...int) (*tensor.Dense, error)

Repeat the value along the axis for the given number of repeats.

func SizeAsDType

func SizeAsDType(x *tensor.Dense, along ...int) (size *tensor.Dense, err error)

SizeAsDType returns the size of a tensor as a tensor along the axis with the same dtype.

func Squeeze

func Squeeze(t *tensor.Dense) error

Squeeze the tensor removing any dimensions of size 1.

func SqueezeShape

func SqueezeShape(shape tensor.Shape) tensor.Shape

SqueezeShape removes any dimensions of size 1.

func StdDev

func StdDev(x *t.Dense, along ...int) (*t.Dense, error)

StdDev is the standard deviation of the tensor along the axis.

y=√(Σ((x-μ)^2)/n)

func ToF32

func ToF32(t *tensor.Dense) (*tensor.Dense, error)

ToF32 will attempt to cast the given tensor int values to float32 vals.

func ZNorm

func ZNorm(x *t.Dense, along ...int) (*t.Dense, error)

ZNorm normalizes x using z-score normalization along the axis.

y=x-μ/σ

func ZeroValue

func ZeroValue(dt t.Dtype) interface{}

ZeroValue for the given datatype.

func Zeros

func Zeros(dt t.Dtype, shape ...int) *t.Dense

Zeros inits a tensor with the given shape and type with zeros.

Types

type EqWidthBinner

type EqWidthBinner struct {
	// Intervals to bin.
	Intervals *tensor.Dense

	// Low values are the lower bounds.
	Low *tensor.Dense

	// High values are the upper bounds.
	High *tensor.Dense
	// contains filtered or unexported fields
}

EqWidthBinner bins values within diminsions to the given intervals.

func NewEqWidthBinner

func NewEqWidthBinner(intervals, low, high *tensor.Dense) (*EqWidthBinner, error)

NewEqWidthBinner creates a new Equal Width Binner.

func (*EqWidthBinner) Bin

func (d *EqWidthBinner) Bin(values *tensor.Dense) (*tensor.Dense, error)

Bin the values.

func (*EqWidthBinner) Bounds

func (d *EqWidthBinner) Bounds() []*tensor.Dense

Bounds used in binning.

func (*EqWidthBinner) Widths

func (d *EqWidthBinner) Widths() *tensor.Dense

Widths used in binning.

type RangedSlice

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

RangedSlice is a ranged slice that implements the Slice interface.

func MakeRangedSlice

func MakeRangedSlice(start, end int, opts ...int) RangedSlice

MakeRangedSlice creates a ranged slice. It takes an optional step param.

func (RangedSlice) End

func (s RangedSlice) End() int

End of the slice.

func (RangedSlice) Start

func (s RangedSlice) Start() int

Start of the slice.

func (RangedSlice) Step

func (s RangedSlice) Step() int

Step of slice.

type SingleSlice

type SingleSlice int

SingleSlice is a single slice, representing this: [start:start+1:0]

func (SingleSlice) End

func (s SingleSlice) End() int

End of the slice.

func (SingleSlice) Start

func (s SingleSlice) Start() int

Start of slice.

func (SingleSlice) Step

func (s SingleSlice) Step() int

Step of slice.

Jump to

Keyboard shortcuts

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